commander 5.0.0 → 6.0.0

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.
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tempfile'
3
+ require 'pathname'
4
4
  require 'shellwords'
5
+ require 'tempfile'
5
6
 
6
7
  module Commander
7
8
  ##
@@ -10,27 +11,13 @@ module Commander
10
11
  # Commander's user interaction module mixes in common
11
12
  # methods which extend HighLine's functionality such
12
13
  # as a #password method rather than calling #ask directly.
13
-
14
14
  module UI
15
15
  module_function
16
16
 
17
- #--
18
- # Auto include growl when available.
19
- #++
20
-
21
- begin
22
- require 'growl'
23
- rescue LoadError
24
- # Do nothing
25
- else
26
- include Growl
27
- end
28
-
29
17
  ##
30
18
  # Ask the user for a password. Specify a custom
31
19
  # _message_ other than 'Password: ' or override the
32
20
  # default _mask_ of '*'.
33
-
34
21
  def password(message = 'Password: ', mask = '*')
35
22
  pass = ask(message) { |q| q.echo = mask }
36
23
  pass = password message, mask if pass.nil? || pass.empty?
@@ -39,10 +26,9 @@ module Commander
39
26
 
40
27
  ##
41
28
  # Choose from a set array of _choices_.
42
-
43
- def choose(message = nil, *choices, &block)
29
+ def choose(message = nil, *choices, &)
44
30
  say message if message
45
- super(*choices, &block)
31
+ super(*choices, &)
46
32
  end
47
33
 
48
34
  ##
@@ -53,7 +39,6 @@ module Commander
53
39
  # remove path/to/old_file.rb
54
40
  # remove path/to/old_file2.rb
55
41
  #
56
-
57
42
  def log(action, *args)
58
43
  say format('%15s %s', action, args.join(' '))
59
44
  end
@@ -65,7 +50,6 @@ module Commander
65
50
  # say_ok 'Everything is fine'
66
51
  # say_ok 'It is ok', 'This is ok too'
67
52
  #
68
-
69
53
  def say_ok(*args)
70
54
  args.each do |arg|
71
55
  say HighLine.default_instance.color(arg, :green)
@@ -79,7 +63,6 @@ module Commander
79
63
  # say_warning 'This is a warning'
80
64
  # say_warning 'Be careful', 'Think about it'
81
65
  #
82
-
83
66
  def say_warning(*args)
84
67
  args.each do |arg|
85
68
  say HighLine.default_instance.color(arg, :yellow)
@@ -93,7 +76,6 @@ module Commander
93
76
  # say_error 'Everything is not fine'
94
77
  # say_error 'It is not ok', 'This is not ok too'
95
78
  #
96
-
97
79
  def say_error(*args)
98
80
  args.each do |arg|
99
81
  say HighLine.default_instance.color(arg, :red)
@@ -113,7 +95,6 @@ module Commander
113
95
  # * color: black blue cyan green magenta red white yellow
114
96
  # * style: blink bold clear underline
115
97
  # * highligh: on_<color>
116
-
117
98
  def color(*args)
118
99
  say HighLine.default_instance.color(*args)
119
100
  end
@@ -135,7 +116,6 @@ module Commander
135
116
  #
136
117
  # * MacOS only
137
118
  #
138
-
139
119
  def speak(message, voice = :Alex, rate = 175)
140
120
  Thread.new { applescript "say #{message.inspect} using #{voice.to_s.inspect} speaking rate #{rate}" }
141
121
  end
@@ -164,10 +144,9 @@ module Commander
164
144
  #
165
145
  # * MacOS only
166
146
  #
167
-
168
147
  def converse(prompt, responses = {})
169
148
  i, commands = 0, responses.map { |_key, value| value.inspect }.join(',')
170
- statement = responses.inject '' do |inner_statement, (key, value)|
149
+ statement = responses.inject(+'') do |inner_statement, (key, value)|
171
150
  inner_statement <<
172
151
  (
173
152
  (i += 1) == 1 ?
@@ -189,7 +168,6 @@ module Commander
189
168
 
190
169
  ##
191
170
  # Execute apple _script_.
192
-
193
171
  def applescript(script)
194
172
  `osascript -e "#{ script.gsub('"', '\"') }"`
195
173
  end
@@ -218,7 +196,6 @@ module Commander
218
196
  # end
219
197
  # end
220
198
  #
221
-
222
199
  def io(input = nil, output = nil, &block)
223
200
  orig_stdin, orig_stdout = $stdin, $stdout
224
201
  $stdin = File.new(input) if input
@@ -226,16 +203,15 @@ module Commander
226
203
  return unless block
227
204
 
228
205
  yield
229
- $stdin, $stdout = orig_stdin, orig_stdout
230
- reset_io
206
+ ensure
207
+ $stdin, $stdout = orig_stdin, orig_stdout if block
231
208
  end
232
209
 
233
210
  ##
234
211
  # Find an editor available in path. Optionally supply the _preferred_
235
212
  # editor. Returns the name as a string, nil if none is available.
236
-
237
213
  def available_editor(preferred = nil)
238
- [preferred, ENV['EDITOR'], 'mate -w', 'vim', 'vi', 'emacs', 'nano', 'pico']
214
+ [preferred, ENV.fetch('EDITOR', nil), 'mate -w', 'vim', 'vi', 'emacs', 'nano', 'pico']
239
215
  .compact
240
216
  .find { |name| system("hash #{name.split.first} 2>&-") }
241
217
  end
@@ -252,7 +228,6 @@ module Commander
252
228
  # ask_editor('foo') # => prompts EDITOR with default text of 'foo'
253
229
  # ask_editor('foo', 'mate -w') # => prompts TextMate with default text of 'foo'
254
230
  #
255
-
256
231
  def ask_editor(input = nil, preferred_editor = nil)
257
232
  editor = available_editor preferred_editor
258
233
  program = Commander::Runner.instance.program(:name).downcase rescue 'commander'
@@ -260,7 +235,7 @@ module Commander
260
235
  begin
261
236
  tmpfile.write input if input
262
237
  tmpfile.close
263
- system("#{editor} #{tmpfile.path.shellescape}") ? IO.read(tmpfile.path) : nil
238
+ system("#{editor} #{tmpfile.path.shellescape}") ? File.read(tmpfile.path) : nil
264
239
  ensure
265
240
  tmpfile.unlink
266
241
  end
@@ -268,7 +243,6 @@ module Commander
268
243
 
269
244
  ##
270
245
  # Enable paging of output after called.
271
-
272
246
  def enable_paging
273
247
  return unless $stdout.tty?
274
248
  return unless Process.respond_to? :fork
@@ -312,7 +286,6 @@ module Commander
312
286
  # res = open uri
313
287
  # end
314
288
  #
315
-
316
289
  def progress(arr, options = {})
317
290
  bar = ProgressBar.new arr.length, options
318
291
  bar.show
@@ -320,10 +293,18 @@ module Commander
320
293
  end
321
294
 
322
295
  ##
323
- # Implements ask_for_CLASS methods.
324
-
296
+ # Implements +ask_for_CLASS+ methods, e.g. +ask_for_float+,
297
+ # +ask_for_date+, or +ask_for_pathname+: each prompts the user via
298
+ # HighLine and parses the response as the requested class. Common
299
+ # classes (Float, Integer, String, Symbol, Regexp, Array, File,
300
+ # Pathname) get explicit methods defined below; any other class that
301
+ # responds to +.parse+ (Date, Time, URI, ...) is resolved dynamically
302
+ # by #method_missing.
325
303
  module AskForClass
326
- DEPRECATED_CONSTANTS = %i[Config TimeoutError MissingSourceFile NIL TRUE FALSE Fixnum Bignum Data].freeze
304
+ # Constants that are either deprecated (and would warn when read via
305
+ # Object.const_get) or simply not meant to be treated as ask_for_*
306
+ # targets; skipped while scanning Object.constants in #method_missing.
307
+ DEPRECATED_CONSTANTS = %i[Config TimeoutError MissingSourceFile NIL TRUE FALSE Fixnum Bignum Data ScanError SortedSet].freeze
327
308
 
328
309
  # define methods for common classes
329
310
  [Float, Integer, String, Symbol, Regexp, Array, File, Pathname].each do |klass|
@@ -332,7 +313,14 @@ module Commander
332
313
  end
333
314
  end
334
315
 
335
- def method_missing(method_name, *arguments, &block)
316
+ ##
317
+ # Handles <tt>ask_for_*</tt> calls not covered by one of the
318
+ # explicitly defined methods above, by searching for a same-named
319
+ # top-level class that implements +.parse+ and asking HighLine to
320
+ # parse the response as that class. Falls through to +super+ (and
321
+ # so ultimately raises NoMethodError) for unrecognized method names
322
+ # or unrecognized classes.
323
+ def method_missing(method_name, *arguments, &)
336
324
  if method_name.to_s =~ /^ask_for_(.*)/
337
325
  if arguments.count != 1
338
326
  fail ArgumentError, "wrong number of arguments (given #{arguments.count}, expected 1)"
@@ -345,10 +333,7 @@ module Commander
345
333
  # Ignore constants that trigger deprecation warnings
346
334
  available_classes = (Object.constants - DEPRECATED_CONSTANTS).map do |const|
347
335
  Object.const_get(const)
348
- rescue RuntimeError
349
- # Rescue errors in Ruby 3 for SortedSet:
350
- # The `SortedSet` class has been extracted from the `set` library.
351
- end.compact.select do |const|
336
+ end.select do |const|
352
337
  const.instance_of?(Class) && const.respond_to?(:parse)
353
338
  end
354
339
 
@@ -370,8 +355,7 @@ module Commander
370
355
 
371
356
  ##
372
357
  # Substitute _hash_'s keys with their associated values in _str_.
373
-
374
- def replace_tokens(str, hash) #:nodoc:
358
+ def replace_tokens(str, hash) # :nodoc:
375
359
  hash.inject(str) do |string, (key, value)|
376
360
  string.gsub ":#{key}", value.to_s
377
361
  end
@@ -412,7 +396,6 @@ module Commander
412
396
  # { :uri => uri } # Can now use :uri within :format option
413
397
  # end
414
398
  #
415
-
416
399
  class ProgressBar
417
400
  ##
418
401
  # Creates a new progress bar.
@@ -438,7 +421,6 @@ module Commander
438
421
  # :time_elapsed
439
422
  # :time_remaining
440
423
  #
441
-
442
424
  def initialize(total, options = {})
443
425
  @total_steps, @step, @start_time = total, 0, Time.now
444
426
  @title = options.fetch :title, 'Progress'
@@ -452,7 +434,6 @@ module Commander
452
434
 
453
435
  ##
454
436
  # Completion percentage.
455
-
456
437
  def percent_complete
457
438
  if @total_steps.zero?
458
439
  100
@@ -463,35 +444,30 @@ module Commander
463
444
 
464
445
  ##
465
446
  # Time that has elapsed since the operation started.
466
-
467
447
  def time_elapsed
468
448
  Time.now - @start_time
469
449
  end
470
450
 
471
451
  ##
472
452
  # Estimated time remaining.
473
-
474
453
  def time_remaining
475
454
  (time_elapsed / @step) * steps_remaining
476
455
  end
477
456
 
478
457
  ##
479
458
  # Number of steps left.
480
-
481
459
  def steps_remaining
482
460
  @total_steps - @step
483
461
  end
484
462
 
485
463
  ##
486
464
  # Formatted progress bar.
487
-
488
465
  def progress_bar
489
466
  (@progress_str * (@width * percent_complete / 100)).ljust @width, @incomplete_str
490
467
  end
491
468
 
492
469
  ##
493
470
  # Generates tokens for this step.
494
-
495
471
  def generate_tokens
496
472
  {
497
473
  title: @title,
@@ -507,7 +483,6 @@ module Commander
507
483
 
508
484
  ##
509
485
  # Output the progress bar.
510
-
511
486
  def show
512
487
  return if finished?
513
488
 
@@ -521,14 +496,12 @@ module Commander
521
496
 
522
497
  ##
523
498
  # Whether or not the operation is complete, and we have finished.
524
-
525
499
  def finished?
526
500
  @step == @total_steps + 1
527
501
  end
528
502
 
529
503
  ##
530
504
  # Whether or not the operation has completed.
531
-
532
505
  def completed?
533
506
  @step == @total_steps
534
507
  end
@@ -536,7 +509,6 @@ module Commander
536
509
  ##
537
510
  # Increment progress. Optionally pass _tokens_ which
538
511
  # can be displayed in the output format.
539
-
540
512
  def increment(tokens = {})
541
513
  @step += 1
542
514
  @tokens.merge! tokens if tokens.is_a? Hash
@@ -545,7 +517,6 @@ module Commander
545
517
 
546
518
  ##
547
519
  # Erase previous terminal line.
548
-
549
520
  def erase_line
550
521
  # highline does not expose the output stream
551
522
  HighLine.default_instance.instance_variable_get('@output').print "\r\e[K"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Commander
4
- VERSION = '5.0.0'
4
+ VERSION = '6.0.0'
5
5
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commander
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
8
8
  - Gabriel Gilder
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-01-15 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: highline
@@ -17,70 +16,14 @@ dependencies:
17
16
  requirements:
18
17
  - - "~>"
19
18
  - !ruby/object:Gem::Version
20
- version: 3.0.0
19
+ version: '3.1'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - "~>"
26
25
  - !ruby/object:Gem::Version
27
- version: 3.0.0
28
- - !ruby/object:Gem::Dependency
29
- name: rake
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
- - !ruby/object:Gem::Dependency
43
- name: rspec
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - "~>"
47
- - !ruby/object:Gem::Version
48
- version: '3.2'
49
- type: :development
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.2'
56
- - !ruby/object:Gem::Dependency
57
- name: rubocop
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: 1.12.1
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: 1.12.1
70
- - !ruby/object:Gem::Dependency
71
- name: simplecov
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
26
+ version: '3.1'
84
27
  description: The complete solution for Ruby command-line executables. Commander bridges
85
28
  the gap between other terminal related libraries you know and love (OptionParser,
86
29
  HighLine), while providing many new features, and an elegant API.
@@ -91,16 +34,16 @@ executables:
91
34
  extensions: []
92
35
  extra_rdoc_files: []
93
36
  files:
37
+ - ".github/workflows/ci.yml"
94
38
  - ".gitignore"
95
39
  - ".rspec"
96
40
  - ".rubocop.yml"
97
41
  - ".rubocop_todo.yml"
98
- - ".travis.yml"
42
+ - ".ruby-version"
99
43
  - DEVELOPMENT
100
44
  - Gemfile
101
45
  - History.rdoc
102
46
  - LICENSE
103
- - Manifest
104
47
  - README.md
105
48
  - Rakefile
106
49
  - bin/commander
@@ -127,26 +70,16 @@ files:
127
70
  - lib/commander/runner.rb
128
71
  - lib/commander/user_interaction.rb
129
72
  - lib/commander/version.rb
130
- - spec/command_spec.rb
131
- - spec/configure_spec.rb
132
- - spec/core_ext/array_spec.rb
133
- - spec/core_ext/object_spec.rb
134
- - spec/help_formatters/terminal_compact_spec.rb
135
- - spec/help_formatters/terminal_spec.rb
136
- - spec/methods_spec.rb
137
- - spec/runner_spec.rb
138
- - spec/spec_helper.rb
139
- - spec/ui_spec.rb
140
73
  homepage: https://github.com/commander-rb/commander
141
74
  licenses:
142
75
  - MIT
143
76
  metadata:
144
77
  bug_tracker_uri: https://github.com/commander-rb/commander/issues
145
78
  changelog_uri: https://github.com/commander-rb/commander/blob/master/History.rdoc
146
- documentation_uri: https://www.rubydoc.info/gems/commander/5.0.0
79
+ documentation_uri: https://www.rubydoc.info/gems/commander/6.0.0
147
80
  homepage_uri: https://github.com/commander-rb/commander
148
- source_code_uri: https://github.com/commander-rb/commander/tree/v5.0.0
149
- post_install_message:
81
+ source_code_uri: https://github.com/commander-rb/commander/tree/v6.0.0
82
+ rubygems_mfa_required: 'true'
150
83
  rdoc_options: []
151
84
  require_paths:
152
85
  - lib
@@ -154,25 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
87
  requirements:
155
88
  - - ">="
156
89
  - !ruby/object:Gem::Version
157
- version: '3.0'
90
+ version: '3.1'
158
91
  required_rubygems_version: !ruby/object:Gem::Requirement
159
92
  requirements:
160
93
  - - ">="
161
94
  - !ruby/object:Gem::Version
162
95
  version: '0'
163
96
  requirements: []
164
- rubygems_version: 3.3.11
165
- signing_key:
97
+ rubygems_version: 4.0.8
166
98
  specification_version: 4
167
99
  summary: The complete solution for Ruby command-line executables
168
- test_files:
169
- - spec/command_spec.rb
170
- - spec/configure_spec.rb
171
- - spec/core_ext/array_spec.rb
172
- - spec/core_ext/object_spec.rb
173
- - spec/help_formatters/terminal_compact_spec.rb
174
- - spec/help_formatters/terminal_spec.rb
175
- - spec/methods_spec.rb
176
- - spec/runner_spec.rb
177
- - spec/spec_helper.rb
178
- - spec/ui_spec.rb
100
+ test_files: []
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- before_install:
4
- - gem update --system
5
- - gem update bundler
6
- rvm:
7
- - 3.0
8
- - 3.1
9
- - 3.2
10
- - 3.3
11
- - jruby
12
- - ruby-head
data/Manifest DELETED
@@ -1,38 +0,0 @@
1
- DEVELOPMENT
2
- History.rdoc
3
- Manifest
4
- README.rdoc
5
- Rakefile
6
- bin/commander
7
- commander.gemspec
8
- lib/commander.rb
9
- lib/commander/blank.rb
10
- lib/commander/command.rb
11
- lib/commander/core_ext.rb
12
- lib/commander/core_ext/array.rb
13
- lib/commander/core_ext/object.rb
14
- lib/commander/delegates.rb
15
- lib/commander/help_formatters.rb
16
- lib/commander/help_formatters/base.rb
17
- lib/commander/help_formatters/terminal.rb
18
- lib/commander/help_formatters/terminal/command_help.erb
19
- lib/commander/help_formatters/terminal/help.erb
20
- lib/commander/help_formatters/terminal_compact.rb
21
- lib/commander/help_formatters/terminal_compact/command_help.erb
22
- lib/commander/help_formatters/terminal_compact/help.erb
23
- lib/commander/import.rb
24
- lib/commander/platform.rb
25
- lib/commander/runner.rb
26
- lib/commander/user_interaction.rb
27
- lib/commander/version.rb
28
- spec/command_spec.rb
29
- spec/core_ext/array_spec.rb
30
- spec/core_ext/object_spec.rb
31
- spec/help_formatters/terminal_spec.rb
32
- spec/runner_spec.rb
33
- spec/spec.opts
34
- spec/spec_helper.rb
35
- spec/ui_spec.rb
36
- tasks/dev_setup.rake
37
- tasks/docs.rake
38
- tasks/gemspec.rake