howzit 2.0.28 → 2.0.29

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: c2a724cc90c349de14afa896512a32d69bcf2fa44575f69e74b0a6f96d615ebb
4
- data.tar.gz: 73c54a8893fa66784575235d329ad698da6e7a34a2741e09d2d93149b118f68a
3
+ metadata.gz: 1e49b8c3399fb8c6aa96f857ea9dd77e8f91b1292783c0b25167ebf9aa380485
4
+ data.tar.gz: 9af75120a0e39cc371bf68f78335be3fcc8ea508e18c64fe5b94d1e9affec4a8
5
5
  SHA512:
6
- metadata.gz: 4d4c9e0c7e5c78f10479cea93dffa09fdf768d335210897feb127f849040bced7a05924a60f6621173ececb1fde116fe5a3ecc79270767c12718b1a1f9742281
7
- data.tar.gz: ff2c18f91883cf4f3b6035b8b304a23575381fd1b9a74333781db8ac000b13d03eb43969bb80d964e3dafeec3556a2152392b2eb074a34561981753233e1fc9e
6
+ metadata.gz: f13f6c1d353c0ef3f8e041a0e3b2864ad808601c5aa4f3423d2830872e26650d29c33fce7b723489ac0557e314e17de8b3aba333a9692dda4e375bd372f17988
7
+ data.tar.gz: 9ebc50f699029414cd72d12ac83a591d6bcbe8f18f1cab175ea6bb81e40baf19b823129c7458947d6d9806448e1018209572f73271ca5c2398ba73f3fa9b9967
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 2.0.29
2
+
3
+ 2022-08-30 04:20
4
+
5
+ #### NEW
6
+
7
+ - --yes flag will answer yes to all prompts when executing
8
+ - --force flag will continue executing directives after an error
9
+
10
+ #### IMPROVED
11
+
12
+ - A non-zero exit status on a run directive will stop processing additional directives
13
+ - A little extra output formatting, more descriptive results logging
14
+
1
15
  ### 2.0.28
2
16
 
3
17
  2022-08-29 18:42
data/bin/howzit CHANGED
@@ -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
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,7 +52,7 @@ 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
@@ -75,7 +78,7 @@ module Howzit
75
78
  matches = Howzit.buildnote.find_topic(@action)
76
79
  raise "Topic not found: #{@action}" if matches.empty?
77
80
 
78
- 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)
79
82
  output.concat(matches[0].run(nested: true))
80
83
  Howzit.console.info("{by}End include: #{matches[0].tasks.count} tasks{x}".c)
81
84
  [output, matches[0].tasks.count]
@@ -86,7 +89,7 @@ module Howzit
86
89
  ##
87
90
  def run_run
88
91
  title = Howzit.options[:show_all_code] ? @action : @title
89
- Howzit.console.info("{bg}Running {bw}#{title}{x}".c)
92
+ Howzit.console.info("#{@prefix}{bg}Running {bw}#{title}{x}".c)
90
93
  return system(@action)
91
94
  end
92
95
 
@@ -95,7 +98,7 @@ module Howzit
95
98
  ##
96
99
  def run_copy
97
100
  title = Howzit.options[:show_all_code] ? @action : @title
98
- 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)
99
102
  Util.os_copy(@action)
100
103
  return true
101
104
  end
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
@@ -66,17 +67,33 @@ module Howzit
66
67
  run_output, total, success = task.run
67
68
 
68
69
  output.concat(run_output)
69
- 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
70
78
 
71
- unless success
72
- Howzit.console.warn '{br}Error running task{bw} - non-zero exit, ending processing{x}'.c
73
- break
79
+ break unless Howzit.options[:force]
74
80
  end
75
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
76
92
  else
77
93
  Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
78
94
  end
79
- 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
80
97
 
81
98
  puts TTY::Box.frame("{bw}#{@postreqs.join("\n\n").wrap(cols - 4)}{x}".c, width: cols) unless @postreqs.empty?
82
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.28'
6
+ VERSION = '2.0.29'
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.28
4
+ version: 2.0.29
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-29 00:00:00.000000000 Z
11
+ date: 2022-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler