howzit 2.0.27 → 2.0.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 135c2149bfce9fb01705564408ded6052edef780b415d1b305e292c6d3701f57
4
- data.tar.gz: c4cfbbd4a6517aa33078c69600f88656ec4c07547c5ff6dcc65cae1151feb47a
3
+ metadata.gz: d66bce7888fe2c4f20b84e2aa89f70ba76103453ff6fe5ed89b385c4debdb170
4
+ data.tar.gz: df96e786640586dbd52345d088118e50f0b56125f86c35431c3acec05df0042f
5
5
  SHA512:
6
- metadata.gz: 3981a7b2eba17397a7e7723105a7f80f7387b04d3a2fabc442fe63a7c27fa79d954801c4527f2168cb557c16e7da865228d8ffb5f7bff55c754c5623010390f6
7
- data.tar.gz: 8cee197d4b84557bddcc5d2584c4784af88ade9424c06cf73d2efdd8735e7675db711d20cfcb98efc91fcb722d91b464aa8a45fa85e0c5c1dd8e8509100460e2
6
+ metadata.gz: 04c1f202b01923c688316b849f1410c50c8d3ae6d0f2e64a17fc5acfcc002f6037e9c29bfdd8f483dea8a710d4fa3ef8d17d91e4c542faeed6dd23b6c3f4cc48
7
+ data.tar.gz: 1d008476828a051cb82a656e9d05b81fa96d6c4939df5aaf5de3bc39456c636c0f71f16979565beaaac056513503a9413a08e4ea43e4634d2386dec3a0ea5af8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ### 2.0.30
2
+
3
+ 2022-08-31 07:15
4
+
5
+ #### FIXED
6
+
7
+ - Formatting of --help and --version commands
8
+
9
+ ### 2.0.29
10
+
11
+ 2022-08-30 04:20
12
+
13
+ #### NEW
14
+
15
+ - --yes flag will answer yes to all prompts when executing
16
+ - --force flag will continue executing directives after an error
17
+
18
+ #### IMPROVED
19
+
20
+ - A non-zero exit status on a run directive will stop processing additional directives
21
+ - A little extra output formatting, more descriptive results logging
22
+
23
+ ### 2.0.28
24
+
25
+ 2022-08-29 18:42
26
+
27
+ #### IMPROVED
28
+
29
+ - If a topic runs multiple directives, stop processing them if one returns a non-zero exit status
30
+
1
31
  ### 2.0.27
2
32
 
3
33
  2022-08-23 12:25
data/bin/howzit CHANGED
@@ -11,7 +11,7 @@ args = parts[0] ? Shellwords.shellsplit(parts[0]) : []
11
11
  Howzit.arguments = parts[1] ? Shellwords.shellsplit(parts[1]) : []
12
12
 
13
13
  OptionParser.new do |opts|
14
- opts.banner = "Usage: #{__FILE__} [OPTIONS] [TOPIC]"
14
+ opts.banner = "Usage: #{File.basename(__FILE__)} [OPTIONS] [TOPIC]"
15
15
  opts.separator ''
16
16
  opts.separator 'Show build notes for the current project (buildnotes.md).
17
17
  Include a topic name to see just that topic, or no argument to display all.'
@@ -20,14 +20,16 @@ OptionParser.new do |opts|
20
20
 
21
21
  opts.separator " Behavior:\n\n" #=================================================================== BEHAVIOR
22
22
 
23
- opts.on('--ask', 'Request confirmation for all tasks when running a topic') do
24
- Howzit.options[:ask] = true
25
- end
23
+ opts.on('--ask', 'Request confirmation for all tasks when running a topic') { Howzit.options[:ask] = true }
26
24
 
27
25
  opts.on('--default', 'Answer all prompts with default response') do
26
+ raise '--default cannot be used with --yes' if Howzit.options[:yes]
27
+
28
28
  Howzit.options[:default] = true
29
29
  end
30
30
 
31
+ opts.on('-f', '--force', 'Continue executing after an error') { Howzit.options[:force] = true }
32
+
31
33
  opts.on('-m', '--matching TYPE', MATCHING_OPTIONS,
32
34
  'Topics matching type', "(#{MATCHING_OPTIONS.join(', ')})") do |c|
33
35
  Howzit.options[:matching] = c
@@ -42,6 +44,12 @@ OptionParser.new do |opts|
42
44
  Howzit.options[:include_upstream] = p
43
45
  end
44
46
 
47
+ opts.on('-y', '--yes', 'Answer yes to all prompts') do
48
+ raise '--default cannot be used with --yes' if Howzit.options[:default]
49
+
50
+ Howzit.options[:yes] = true
51
+ end
52
+
45
53
  opts.separator "\n Listing:\n\n" #=================================================================== LISTING
46
54
 
47
55
  opts.on('-L', '--list-completions', 'List topics (completion-compatible)') do
@@ -225,7 +233,7 @@ OptionParser.new do |opts|
225
233
  end
226
234
 
227
235
  opts.on('-v', '--version', 'Display version number') do
228
- puts "how v#{Howzit::VERSION}"
236
+ puts "#{File.basename(__FILE__)} v#{Howzit::VERSION}"
229
237
  Process.exit 0
230
238
  end
231
239
  end.parse!(args)
data/lib/howzit/colors.rb CHANGED
@@ -227,7 +227,7 @@ module Howzit
227
227
  def template(input)
228
228
  input = input.join(' ') if input.is_a? Array
229
229
  fmt = input.gsub(/%/, '%%')
230
- fmt = fmt.gsub(/\{(\w+)\}/) do
230
+ fmt = fmt.gsub(/(?<!\\u)\{(\w+)\}/i) do
231
231
  Regexp.last_match(1).split('').map { |c| "%<#{c}>s" }.join('')
232
232
  end
233
233
 
data/lib/howzit/config.rb CHANGED
@@ -91,6 +91,7 @@ module Howzit
91
91
  choose: false,
92
92
  default: false,
93
93
  for_topic: nil,
94
+ force: false,
94
95
  grep: nil,
95
96
  list_runnable: false,
96
97
  list_runnable_titles: false,
@@ -99,7 +100,8 @@ module Howzit
99
100
  quiet: false,
100
101
  run: false,
101
102
  title_only: false,
102
- verbose: false
103
+ verbose: false,
104
+ yes: false
103
105
  }
104
106
 
105
107
  config = load_config
data/lib/howzit/prompt.rb CHANGED
@@ -18,6 +18,8 @@ module Howzit
18
18
  def yn(prompt, default: true)
19
19
  return default unless $stdout.isatty
20
20
 
21
+ return true if Howzit.options[:yes]
22
+
21
23
  return default if Howzit.options[:default]
22
24
 
23
25
  tty_state = `stty -g`
data/lib/howzit/task.rb CHANGED
@@ -19,6 +19,9 @@ module Howzit
19
19
  ## @option attributes :action [String] task action
20
20
  ## @option attributes :parent [String] title of nested (included) topic origin
21
21
  def initialize(attributes, optional: false, default: true)
22
+ @prefix = "{bw}\u{25B7}\u{25B7} {x}"
23
+ # arrow = "{bw}\u{279F}{x}"
24
+
22
25
  @type = attributes[:type] || :run
23
26
  @title = attributes[:title] || nil
24
27
  @action = attributes[:action].render_arguments || nil
@@ -49,18 +52,20 @@ module Howzit
49
52
  ## Execute a block type
50
53
  ##
51
54
  def run_block
52
- Howzit.console.info "{bg}Running block {bw}#{@title}{x}".c if Howzit.options[:log_level] < 2
55
+ Howzit.console.info "#{@prefix}{bg}Running block {bw}#{@title}{x}".c if Howzit.options[:log_level] < 2
53
56
  block = @action
54
57
  script = Tempfile.new('howzit_script')
55
58
  begin
56
59
  script.write(block)
57
60
  script.close
58
61
  File.chmod(0o777, script.path)
59
- system(%(/bin/sh -c "#{script.path}"))
62
+ res = system(%(/bin/sh -c "#{script.path}"))
60
63
  ensure
61
64
  script.close
62
65
  script.unlink
63
66
  end
67
+
68
+ res
64
69
  end
65
70
 
66
71
  ##
@@ -73,7 +78,7 @@ module Howzit
73
78
  matches = Howzit.buildnote.find_topic(@action)
74
79
  raise "Topic not found: #{@action}" if matches.empty?
75
80
 
76
- Howzit.console.info("{by}Running tasks from {bw}#{matches[0].title}{x}".c)
81
+ Howzit.console.info("#{@prefix}{by}Running tasks from {bw}#{matches[0].title}{x}".c)
77
82
  output.concat(matches[0].run(nested: true))
78
83
  Howzit.console.info("{by}End include: #{matches[0].tasks.count} tasks{x}".c)
79
84
  [output, matches[0].tasks.count]
@@ -84,8 +89,8 @@ module Howzit
84
89
  ##
85
90
  def run_run
86
91
  title = Howzit.options[:show_all_code] ? @action : @title
87
- Howzit.console.info("{bg}Running {bw}#{title}{x}".c)
88
- system(@action)
92
+ Howzit.console.info("#{@prefix}{bg}Running {bw}#{title}{x}".c)
93
+ return system(@action)
89
94
  end
90
95
 
91
96
  ##
@@ -93,8 +98,9 @@ module Howzit
93
98
  ##
94
99
  def run_copy
95
100
  title = Howzit.options[:show_all_code] ? @action : @title
96
- Howzit.console.info("{bg}Copied {bw}#{title}{bg} to clipboard{x}".c)
101
+ Howzit.console.info("#{@prefix}{bg}Copied {bw}#{title}{bg} to clipboard{x}".c)
97
102
  Util.os_copy(@action)
103
+ return true
98
104
  end
99
105
 
100
106
  ##
@@ -103,22 +109,22 @@ module Howzit
103
109
  def run
104
110
  output = []
105
111
  tasks = 1
106
- if @type == :block
107
- run_block
108
- else
109
- case @type
110
- when :include
111
- output, tasks = run_include
112
- when :run
113
- run_run
114
- when :copy
115
- run_copy
116
- when :open
117
- Util.os_open(@action)
118
- end
119
- end
112
+ res = if @type == :block
113
+ run_block
114
+ else
115
+ case @type
116
+ when :include
117
+ output, tasks = run_include
118
+ when :run
119
+ run_run
120
+ when :copy
121
+ run_copy
122
+ when :open
123
+ Util.os_open(@action)
124
+ end
125
+ end
120
126
 
121
- [output, tasks]
127
+ [output, tasks, res]
122
128
  end
123
129
 
124
130
  ##
data/lib/howzit/topic.rb CHANGED
@@ -7,7 +7,7 @@ module Howzit
7
7
 
8
8
  attr_accessor :content
9
9
 
10
- attr_reader :title, :tasks, :prereqs, :postreqs
10
+ attr_reader :title, :tasks, :prereqs, :postreqs, :results
11
11
 
12
12
  ##
13
13
  ## Initialize a topic object
@@ -21,6 +21,7 @@ module Howzit
21
21
  @parent = nil
22
22
  @nest_level = 0
23
23
  @tasks = gather_tasks
24
+ @results = { total: 0, success: 0, errors: 0, message: ''.c }
24
25
  end
25
26
 
26
27
  ##
@@ -35,7 +36,7 @@ module Howzit
35
36
  # Handle run command, execute directives in topic
36
37
  def run(nested: false)
37
38
  output = []
38
- tasks = 0
39
+
39
40
  cols = begin
40
41
  TTY::Screen.columns > 60 ? 60 : TTY::Screen.columns
41
42
  rescue StandardError
@@ -63,14 +64,36 @@ module Howzit
63
64
  next unless res
64
65
 
65
66
  end
66
- run_output, total = task.run
67
+ run_output, total, success = task.run
68
+
67
69
  output.concat(run_output)
68
- tasks += total
70
+ @results[:total] += total
71
+
72
+ if success
73
+ @results[:success] += total
74
+ else
75
+ Howzit.console.warn %({bw}\u{2297} {br}Error running task {bw}"#{task.title}"{x}).c
76
+
77
+ @results[:errors] += total
78
+
79
+ break unless Howzit.options[:force]
80
+ end
69
81
  end
82
+
83
+ total = "{bw}#{@results[:total]}{by} #{@results[:total] == 1 ? 'task' : 'tasks'}".c
84
+ errors = "{bw}#{@results[:errors]}{by} #{@results[:errors] == 1 ? 'error' : 'errors'}".c
85
+ @results[:message] += if @results[:errors].zero?
86
+ "{bg}\u{2713} {by}Ran #{total}{x}"
87
+ elsif Howzit.options[:force]
88
+ "{br}\u{2715} {by}Completed #{total} with #{errors}{x}".c
89
+ else
90
+ "{br}\u{2715} {by}Ran #{total}, terminated due to error{x}".c
91
+ end
70
92
  else
71
93
  Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
72
94
  end
73
- output.push("{bm}Ran #{tasks} #{tasks == 1 ? 'task' : 'tasks'}{x}".c) if Howzit.options[:log_level] < 2 && !nested
95
+
96
+ output.push(@results[:message]) if Howzit.options[:log_level] < 2 && !nested
74
97
 
75
98
  puts TTY::Box.frame("{bw}#{@postreqs.join("\n\n").wrap(cols - 4)}{x}".c, width: cols) unless @postreqs.empty?
76
99
 
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.27'
6
+ VERSION = '2.0.30'
7
7
  end
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.27
4
+ version: 2.0.30
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-23 00:00:00.000000000 Z
11
+ date: 2022-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler