howzit 2.0.7 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/howzit/topic.rb CHANGED
@@ -9,6 +9,12 @@ module Howzit
9
9
 
10
10
  attr_reader :title, :tasks, :prereqs, :postreqs
11
11
 
12
+ ##
13
+ ## Initialize a topic object
14
+ ##
15
+ ## @param title [String] The topic title
16
+ ## @param content [String] The raw topic content
17
+ ##
12
18
  def initialize(title, content)
13
19
  @title = title
14
20
  @content = content
@@ -17,18 +23,29 @@ module Howzit
17
23
  @tasks = gather_tasks
18
24
  end
19
25
 
26
+ ##
27
+ ## Search title and contents for a pattern
28
+ ##
29
+ ## @param term [String] the search pattern
30
+ ##
20
31
  def grep(term)
21
32
  @title =~ /#{term}/i || @content =~ /#{term}/i
22
33
  end
23
34
 
24
- # Handle run command, execute directives
35
+ # Handle run command, execute directives in topic
25
36
  def run(nested: false)
26
37
  output = []
27
38
  tasks = 0
39
+ cols = begin
40
+ TTY::Screen.columns > 60 ? 60 : TTY::Screen.columns
41
+ rescue StandardError
42
+ 60
43
+ end
44
+
28
45
  if @tasks.count.positive?
29
46
  unless @prereqs.empty?
30
- puts @prereqs.join("\n\n")
31
- res = Prompt.yn('This topic has prerequisites, have they been met?', default: true)
47
+ puts TTY::Box.frame("{by}#{@prereqs.join("\n\n").wrap(cols - 4)}{x}".c, width: cols)
48
+ res = Prompt.yn('Have the above prerequisites been met?', default: true)
32
49
  Process.exit 1 unless res
33
50
 
34
51
  end
@@ -85,7 +102,7 @@ module Howzit
85
102
  end
86
103
  output.push("{bm}Ran #{tasks} #{tasks == 1 ? 'task' : 'tasks'}{x}".c) if Howzit.options[:log_level] < 2 && !nested
87
104
 
88
- puts postreqs.join("\n\n") unless postreqs.empty?
105
+ puts TTY::Box.frame("{bw}#{@postreqs.join("\n\n").wrap(cols - 4)}{x}".c, width: cols) unless @postreqs.empty?
89
106
 
90
107
  output
91
108
  end
data/lib/howzit/util.rb CHANGED
@@ -1,21 +1,26 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Howzit
4
+ # Util class
2
5
  module Util
3
6
  class << self
7
+ def read_file(path)
8
+ IO.read(path).force_encoding('utf-8').strip
9
+ end
10
+
4
11
  def valid_command?(command)
5
12
  cmd = command.split(' ')[0]
6
13
  command_exist?(cmd)
7
14
  end
8
-
15
+
9
16
  def command_exist?(command)
10
17
  exts = ENV.fetch('PATHEXT', '').split(::File::PATH_SEPARATOR)
11
18
  if Pathname.new(command).absolute?
12
- ::File.exist?(command) ||
13
- exts.any? { |ext| ::File.exist?("#{command}#{ext}") }
19
+ ::File.exist?(command) || exts.any? { |ext| ::File.exist?("#{command}#{ext}") }
14
20
  else
15
21
  ENV.fetch('PATH', '').split(::File::PATH_SEPARATOR).any? do |dir|
16
22
  file = ::File.join(dir, command)
17
- ::File.exist?(file) ||
18
- exts.any? { |ext| ::File.exist?("#{file}#{ext}") }
23
+ ::File.exist?(file) || exts.any? { |ext| ::File.exist?("#{file}#{ext}") }
19
24
  end
20
25
  end
21
26
  end
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.7'
6
+ VERSION = '2.0.10'
7
7
  end
data/lib/howzit.rb CHANGED
@@ -21,15 +21,28 @@ require 'tempfile'
21
21
  require 'yaml'
22
22
 
23
23
  require 'tty/screen'
24
+ require 'tty/box'
24
25
  # require 'tty/prompt'
25
26
 
27
+ # Main config dir
26
28
  CONFIG_DIR = '~/.config/howzit'
29
+
30
+ # Config file name
27
31
  CONFIG_FILE = 'howzit.yaml'
32
+
33
+ # Ignore file name
28
34
  IGNORE_FILE = 'ignore.yaml'
35
+
36
+ # Available options for matching method
29
37
  MATCHING_OPTIONS = %w[partial exact fuzzy beginswith].freeze
38
+
39
+ # Available options for multiple_matches method
30
40
  MULTIPLE_OPTIONS = %w[first best all choose].freeze
41
+
42
+ # Available options for header formatting
31
43
  HEADER_FORMAT_OPTIONS = %w[border block].freeze
32
44
 
45
+ # Main module for howzit
33
46
  module Howzit
34
47
  class << self
35
48
  attr_accessor :arguments, :cli_args
data/spec/cli_spec.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ # https://github.com/thoiberg/cli-test
6
+ describe 'CLI' do
7
+ include CliTest
8
+
9
+ it 'executes successfully' do
10
+ execute_script('bin/howzit', use_bundler: true)
11
+ expect(last_execution).to be_successful
12
+ end
13
+
14
+ it 'lists available topics' do
15
+ execute_script('bin/howzit', use_bundler: true, args: %w[-L])
16
+ expect(last_execution).to be_successful
17
+ expect(last_execution.stdout).to match(/Topic Balogna/)
18
+ expect(last_execution.stdout.split(/\n/).count).to eq 3
19
+ end
20
+
21
+ it 'lists available tasks' do
22
+ execute_script('bin/howzit', use_bundler: true, args: %w[-T])
23
+ expect(last_execution).to be_successful
24
+ expect(last_execution.stdout).to match(/Topic Balogna/)
25
+ expect(last_execution.stdout.split(/\n/).count).to eq 2
26
+ end
27
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,6 +10,7 @@
10
10
  # end
11
11
 
12
12
  require 'howzit'
13
+ require 'cli-test'
13
14
 
14
15
  RSpec.configure do |c|
15
16
  c.expect_with(:rspec) { |e| e.syntax = :expect }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.7
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-04 00:00:00.000000000 Z
11
+ date: 2022-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '3.1'
139
+ - !ruby/object:Gem::Dependency
140
+ name: cli-test
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: simplecov
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -240,6 +254,20 @@ dependencies:
240
254
  - - "~>"
241
255
  - !ruby/object:Gem::Version
242
256
  version: '0.8'
257
+ - !ruby/object:Gem::Dependency
258
+ name: tty-box
259
+ requirement: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '0.7'
264
+ type: :runtime
265
+ prerelease: false
266
+ version_requirements: !ruby/object:Gem::Requirement
267
+ requirements:
268
+ - - "~>"
269
+ - !ruby/object:Gem::Version
270
+ version: '0.7'
243
271
  description: Command line project documentation and task runner
244
272
  email:
245
273
  - me@brettterpstra.com
@@ -269,7 +297,6 @@ files:
269
297
  - lib/.rubocop.yml
270
298
  - lib/howzit.rb
271
299
  - lib/howzit/buildnote.rb
272
- - lib/howzit/buildnotes.rb
273
300
  - lib/howzit/colors.rb
274
301
  - lib/howzit/config.rb
275
302
  - lib/howzit/console_logger.rb
@@ -283,6 +310,7 @@ files:
283
310
  - spec/.rubocop.yml
284
311
  - spec/buildnote_spec.rb
285
312
  - spec/buildnotes.md.bak
313
+ - spec/cli_spec.rb
286
314
  - spec/ruby_gem_spec.rb
287
315
  - spec/spec_helper.rb
288
316
  - spec/task_spec.rb
@@ -316,6 +344,7 @@ test_files:
316
344
  - spec/.rubocop.yml
317
345
  - spec/buildnote_spec.rb
318
346
  - spec/buildnotes.md.bak
347
+ - spec/cli_spec.rb
319
348
  - spec/ruby_gem_spec.rb
320
349
  - spec/spec_helper.rb
321
350
  - spec/task_spec.rb