commander 4.3.8 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +1 -1
- data/History.rdoc +6 -0
- data/README.md +4 -0
- data/bin/commander +60 -11
- data/lib/commander/runner.rb +17 -1
- data/lib/commander/version.rb +1 -1
- data/spec/runner_spec.rb +56 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e9fa3f3fbb6475cdf02ae043991c17ec9058107
|
4
|
+
data.tar.gz: 39f8b6530783b95688fa20d4b6ac4b7bb43ec0ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 612b57dc06491d404d072a6e8eec9da8c1727e65fe23afa48c36c183e7ff706de9cb1c4bc3f5adfef67d03ee2be9ac8dab0f9eb6328dbfe758479c9ead834a0f
|
7
|
+
data.tar.gz: 2141c0258fd8b2818c7f3eacf02809a32dcc68326822920bb8756215ab777bb46d10b58848d959eeb8b95da864d150331e79d15f61ab938b4fef946b6b9d008e
|
data/.rubocop_todo.yml
CHANGED
data/History.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
=== 4.4.0 / 2016-02-19
|
2
|
+
|
3
|
+
* Add modular style template initialization. (@lebogan)
|
4
|
+
* Allow option names that start with a global option name.
|
5
|
+
* Fix handling of negatable global flags. (@mfurtak)
|
6
|
+
|
1
7
|
=== 4.3.8 / 2016-02-09
|
2
8
|
|
3
9
|
* Fix regression for deprecation warnings.
|
data/README.md
CHANGED
@@ -37,6 +37,10 @@ To generate a quick template for a commander app, run:
|
|
37
37
|
|
38
38
|
$ commander init yourfile.rb
|
39
39
|
|
40
|
+
To generate a quick modular style template for a commander app, run:
|
41
|
+
|
42
|
+
$ commander init --modular yourfile.rb
|
43
|
+
|
40
44
|
## Example
|
41
45
|
|
42
46
|
For more option examples view the `Commander::Command#option` method. Also
|
data/bin/commander
CHANGED
@@ -8,30 +8,78 @@ program :version, Commander::VERSION
|
|
8
8
|
program :description, 'Commander utility program.'
|
9
9
|
|
10
10
|
command :init do |c|
|
11
|
-
c.syntax = 'commander init <file>'
|
11
|
+
c.syntax = 'commander init [option] <file>'
|
12
12
|
c.summary = 'Initialize a commander template'
|
13
13
|
c.description = 'Initialize an empty <file> with a commander template,
|
14
14
|
allowing very quick creation of commander executables.'
|
15
|
-
c.example 'Create a new
|
16
|
-
c.
|
15
|
+
c.example 'Create a new classic style template file.', 'commander init bin/my_executable'
|
16
|
+
c.example 'Create a new modular style template file.', 'commander init --modular bin/my_executable'
|
17
|
+
c.option '-m', '--modular', 'Initialize a modular style template'
|
18
|
+
c.action do |args, options|
|
17
19
|
file = args.shift || abort('file argument required.')
|
18
20
|
name = ask 'Machine name of program: '
|
19
21
|
description = ask 'Describe your program: '
|
20
22
|
commands = ask_for_array 'List the commands you wish to create: '
|
21
23
|
begin
|
22
|
-
|
23
|
-
|
24
|
+
if options.modular
|
25
|
+
File.open(file, 'w') do |f|
|
26
|
+
f.write <<-"...".gsub!(/^ {10}/, '')
|
27
|
+
#!/usr/bin/env ruby
|
28
|
+
|
29
|
+
require 'rubygems'
|
30
|
+
require 'commander'
|
31
|
+
|
32
|
+
class MyApplication
|
33
|
+
include Commander::Methods
|
34
|
+
# include whatever modules you need
|
35
|
+
|
36
|
+
def run
|
37
|
+
program :name, '#{name}'
|
38
|
+
program :version, '0.0.1'
|
39
|
+
program :description, '#{description}'
|
40
|
+
|
41
|
+
...
|
42
|
+
commands.each do |command|
|
43
|
+
f.write <<-"...".gsub!(/^ {12}/, '')
|
44
|
+
command :#{command} do |c|
|
45
|
+
c.syntax = '#{name} #{command} [options]'
|
46
|
+
c.summary = ''
|
47
|
+
c.description = ''
|
48
|
+
c.example 'description', 'command example'
|
49
|
+
c.option '--some-switch', 'Some switch that does something'
|
50
|
+
c.action do |args, options|
|
51
|
+
# Do something or c.when_called #{name.capitalize}::Commands::#{command.capitalize}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
...
|
56
|
+
end
|
57
|
+
f.write <<-"...".gsub!(/^ {12}/, '')
|
58
|
+
run!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
MyApplication.new.run if $0 == __FILE__
|
63
|
+
...
|
64
|
+
end
|
65
|
+
|
66
|
+
File.chmod(0755, file)
|
67
|
+
say "Initialized modular template in #{file}"
|
68
|
+
else
|
69
|
+
File.open(file, 'w') do |f|
|
70
|
+
f.write <<-"...".gsub!(/^ {10}/, '')
|
24
71
|
#!/usr/bin/env ruby
|
25
72
|
|
26
73
|
require 'rubygems'
|
27
74
|
require 'commander/import'
|
28
75
|
|
76
|
+
program :name, '#{name}'
|
29
77
|
program :version, '0.0.1'
|
30
78
|
program :description, '#{description}'
|
31
79
|
|
32
|
-
|
33
|
-
|
34
|
-
|
80
|
+
...
|
81
|
+
commands.each do |command|
|
82
|
+
f.write <<-"...".gsub!(/^ {12}/, '')
|
35
83
|
command :#{command} do |c|
|
36
84
|
c.syntax = '#{name} #{command} [options]'
|
37
85
|
c.summary = ''
|
@@ -43,11 +91,12 @@ command :init do |c|
|
|
43
91
|
end
|
44
92
|
end
|
45
93
|
|
46
|
-
|
94
|
+
...
|
95
|
+
end
|
47
96
|
end
|
97
|
+
File.chmod 0755, file
|
98
|
+
say "Initialized template in #{file}"
|
48
99
|
end
|
49
|
-
File.chmod 0755, file
|
50
|
-
say "Initialized template in #{file}"
|
51
100
|
rescue => e
|
52
101
|
abort e
|
53
102
|
end
|
data/lib/commander/runner.rb
CHANGED
@@ -335,9 +335,11 @@ module Commander
|
|
335
335
|
switches.map! { |s| s[0, s.index('=') || s.index(' ') || s.length] }
|
336
336
|
end
|
337
337
|
|
338
|
+
switches = expand_optionally_negative_switches(switches)
|
339
|
+
|
338
340
|
past_switch, arg_removed = false, false
|
339
341
|
args.delete_if do |arg|
|
340
|
-
if switches.any? { |s|
|
342
|
+
if switches.any? { |s| s[0, arg.length] == arg }
|
341
343
|
arg_removed = !switch_has_arg
|
342
344
|
past_switch = true
|
343
345
|
elsif past_switch && !arg_removed && arg !~ /^-/
|
@@ -350,6 +352,20 @@ module Commander
|
|
350
352
|
end
|
351
353
|
end
|
352
354
|
|
355
|
+
# expand switches of the style '--[no-]blah' into both their
|
356
|
+
# '--blah' and '--no-blah' variants, so that they can be
|
357
|
+
# properly detected and removed
|
358
|
+
def expand_optionally_negative_switches(switches)
|
359
|
+
switches.reduce([]) do |memo, val|
|
360
|
+
if val =~ /\[no-\]/
|
361
|
+
memo << val.gsub(/\[no-\]/, '')
|
362
|
+
memo << val.gsub(/\[no-\]/, 'no-')
|
363
|
+
else
|
364
|
+
memo << val
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
353
369
|
##
|
354
370
|
# Parse global command options.
|
355
371
|
|
data/lib/commander/version.rb
CHANGED
data/spec/runner_spec.rb
CHANGED
@@ -110,6 +110,28 @@ describe Commander do
|
|
110
110
|
end.run!
|
111
111
|
expect(quiet).to be true
|
112
112
|
end
|
113
|
+
|
114
|
+
it 'should be inherited by commands when the positive form of a [no-] option' do
|
115
|
+
quiet = nil
|
116
|
+
new_command_runner 'foo', '--quiet' do
|
117
|
+
global_option('--[no-]quiet', 'Suppress output') {}
|
118
|
+
command :foo do |c|
|
119
|
+
c.when_called { |_, options| quiet = options.quiet }
|
120
|
+
end
|
121
|
+
end.run!
|
122
|
+
expect(quiet).to be true
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should be inherited by commands when the negative form of a [no-] option' do
|
126
|
+
quiet = nil
|
127
|
+
new_command_runner 'foo', '--no-quiet' do
|
128
|
+
global_option('--[no-]quiet', 'Suppress output') {}
|
129
|
+
command :foo do |c|
|
130
|
+
c.when_called { |_, options| quiet = options.quiet }
|
131
|
+
end
|
132
|
+
end.run!
|
133
|
+
expect(quiet).to be false
|
134
|
+
end
|
113
135
|
end
|
114
136
|
|
115
137
|
describe '#parse_global_options' do
|
@@ -270,6 +292,40 @@ describe Commander do
|
|
270
292
|
command_runner.remove_global_options options, args
|
271
293
|
expect(args).to eq(%w(alpha beta))
|
272
294
|
end
|
295
|
+
|
296
|
+
it 'should remove a switch that is the positive form of the [no-] option' do
|
297
|
+
options, args = [], []
|
298
|
+
options << { switches: ['-g', '--[no-]good'] }
|
299
|
+
options << { switches: ['-y', '--yes ARG'] }
|
300
|
+
options << { switches: ['-a', '--alternative=ARG'] }
|
301
|
+
args << '--good' << 'alpha'
|
302
|
+
args << '--yes' << 'deleted'
|
303
|
+
args << '-a' << 'deleted'
|
304
|
+
args << 'beta'
|
305
|
+
command_runner.remove_global_options options, args
|
306
|
+
expect(args).to eq(%w(alpha beta))
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'should remove a switch that is the negative form of the [no-] option' do
|
310
|
+
options, args = [], []
|
311
|
+
options << { switches: ['-g', '--[no-]good'] }
|
312
|
+
options << { switches: ['-y', '--yes ARG'] }
|
313
|
+
options << { switches: ['-a', '--alternative=ARG'] }
|
314
|
+
args << '--no-good' << 'alpha'
|
315
|
+
args << '--yes' << 'deleted'
|
316
|
+
args << '-a' << 'deleted'
|
317
|
+
args << 'beta'
|
318
|
+
command_runner.remove_global_options options, args
|
319
|
+
expect(args).to eq(%w(alpha beta))
|
320
|
+
end
|
321
|
+
|
322
|
+
it 'should not remove options that start with a global option name' do
|
323
|
+
options, args = [], []
|
324
|
+
options << { switches: ['-v', '--version'] }
|
325
|
+
args << '--versionCode' << 'something'
|
326
|
+
command_runner.remove_global_options options, args
|
327
|
+
expect(args).to eq(%w(--versionCode something))
|
328
|
+
end
|
273
329
|
end
|
274
330
|
|
275
331
|
describe '--trace' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-02-
|
12
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: highline
|