commander 4.0.7 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/History.rdoc +31 -33
- data/commander.gemspec +3 -2
- data/lib/commander/command.rb +4 -2
- data/lib/commander/version.rb +1 -1
- data/spec/command_spec.rb +36 -12
- data/spec/runner_spec.rb +25 -1
- data/spec/spec_helper.rb +3 -0
- metadata +11 -11
data/.travis.yml
CHANGED
data/History.rdoc
CHANGED
@@ -1,49 +1,47 @@
|
|
1
|
-
4.0
|
2
|
-
==================
|
1
|
+
=== 4.1.0 / 2012-02-12
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
* Reorganized help output to display synopsis before description (issue #12).
|
3
|
+
* Update highline dependency.
|
4
|
+
* Make optional arguments true when present (issue #2).
|
7
5
|
|
8
|
-
4.0.
|
9
|
-
==================
|
6
|
+
=== 4.0.7 / 2012-01-23
|
10
7
|
|
11
|
-
|
12
|
-
|
8
|
+
* Improved support for JRuby and Windows (and any other platforms that don't support Kernel.fork).
|
9
|
+
* Fixed bug #33 - support `--help` after commands.
|
10
|
+
* Reorganized help output to display synopsis before description (issue #12).
|
13
11
|
|
14
|
-
4.0.
|
15
|
-
==================
|
12
|
+
=== 4.0.6 / 2011-09-15
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
* Added say_ok, say_warning and say_error methods to print messages in green, yellow or red. (thanks to Simon Courtois)
|
20
|
-
* Fixed; Allow global options to be passed in any order, even mixed with command options. (thanks to Rich Grundy)
|
21
|
-
* Fixed; Global options can be passed before or after the command, they can even be mixed with command options. Closes #8. (thanks to Rich Grundy)
|
22
|
-
* Fixed; Platform test should now correctly identify JRuby. (thanks to Justin Lynn)
|
23
|
-
* Fixed; Add to_s to exceptions as option parser no longer does implicit conversion. (thanks to Justin Lynn)
|
14
|
+
* Improved load time on Ruby 1.9. (thanks to Jonathon M. Abbott)
|
15
|
+
* Updated documentation.
|
24
16
|
|
25
|
-
4.0.
|
26
|
-
==================
|
17
|
+
=== 4.0.5 / 2011-08-09
|
27
18
|
|
28
|
-
|
29
|
-
|
19
|
+
* Updated documentation to fix inaccuracies and unclear information.
|
20
|
+
* Improved rake tasks for gem development.
|
21
|
+
* Added say_ok, say_warning and say_error methods to print messages in green, yellow or red. (thanks to Simon Courtois)
|
22
|
+
* Fixed; Allow global options to be passed in any order, even mixed with command options. (thanks to Rich Grundy)
|
23
|
+
* Fixed; Global options can be passed before or after the command, they can even be mixed with command options. Closes #8. (thanks to Rich Grundy)
|
24
|
+
* Fixed; Platform test should now correctly identify JRuby. (thanks to Justin Lynn)
|
25
|
+
* Fixed; Add to_s to exceptions as option parser no longer does implicit conversion. (thanks to Justin Lynn)
|
30
26
|
|
31
|
-
4.0.
|
32
|
-
==================
|
27
|
+
=== 4.0.4 / 2011-04-04
|
33
28
|
|
34
|
-
|
29
|
+
* Fixed program(:key) behavior for non-Array keys like name, version, description under Ruby 1.9
|
30
|
+
* All specs should pass under Ruby 1.9 now
|
35
31
|
|
36
|
-
4.0.
|
37
|
-
==================
|
32
|
+
=== 4.0.3 / 2010-04-06
|
38
33
|
|
39
|
-
|
40
|
-
* Fixed; ProgressBar immediately shows, and doesn't die on empty lists.
|
34
|
+
* Fixed global_option which was consuming arguments when not expected. Closes #22
|
41
35
|
|
42
|
-
4.0.
|
43
|
-
==================
|
36
|
+
=== 4.0.2 / 2010-01-19
|
44
37
|
|
45
|
-
|
46
|
-
|
38
|
+
* Added program(:int_block) to allow a block to be run on interrupt.
|
39
|
+
* Fixed; ProgressBar immediately shows, and doesn't die on empty lists.
|
40
|
+
|
41
|
+
=== 4.0.1 / 2010-01-14
|
42
|
+
|
43
|
+
* Fixed commander when using JRuby
|
44
|
+
* Fixed template; should require "commander/import"
|
47
45
|
|
48
46
|
=== 4.0.0 / 2009-10-10
|
49
47
|
|
data/commander.gemspec
CHANGED
@@ -18,8 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
-
s.add_runtime_dependency("highline", "~> 1.
|
21
|
+
s.add_runtime_dependency("highline", "~> 1.6.11")
|
22
|
+
|
22
23
|
s.add_development_dependency("rspec", "~> 2")
|
23
24
|
s.add_development_dependency("rake")
|
24
25
|
s.add_development_dependency("simplecov")
|
25
|
-
end
|
26
|
+
end
|
data/lib/commander/command.rb
CHANGED
@@ -107,7 +107,7 @@ module Commander
|
|
107
107
|
#
|
108
108
|
|
109
109
|
def option *args, &block
|
110
|
-
switches, description = Runner.separate_switches_from_description
|
110
|
+
switches, description = Runner.separate_switches_from_description(*args)
|
111
111
|
proc = block || option_proc(switches)
|
112
112
|
@options << {
|
113
113
|
:args => args,
|
@@ -164,7 +164,7 @@ module Commander
|
|
164
164
|
def parse_options_and_call_procs *args
|
165
165
|
return args if args.empty?
|
166
166
|
@options.inject OptionParser.new do |opts, option|
|
167
|
-
opts.on
|
167
|
+
opts.on(*option[:args], &option[:proc])
|
168
168
|
opts
|
169
169
|
end.parse! args
|
170
170
|
end
|
@@ -189,6 +189,8 @@ module Commander
|
|
189
189
|
|
190
190
|
def proxy_option_struct
|
191
191
|
proxy_options.inject Options.new do |options, (option, value)|
|
192
|
+
# options that are present will evaluate to true
|
193
|
+
value = true if value.nil?
|
192
194
|
options.__send__ :"#{option}=", value
|
193
195
|
options
|
194
196
|
end
|
data/lib/commander/version.rb
CHANGED
data/spec/command_spec.rb
CHANGED
@@ -89,20 +89,44 @@ describe Commander::Command do
|
|
89
89
|
@command.when_called { |_, options| options.file.should eq('foo') }
|
90
90
|
@command.run '--file', 'foo'
|
91
91
|
lambda { @command.run '--file' }.should raise_error(OptionParser::MissingArgument)
|
92
|
-
end
|
92
|
+
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
94
|
+
describe "optional arguments" do
|
95
|
+
before do
|
96
|
+
@command.option '--use-config [file] '
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return the argument when provided" do
|
100
|
+
@command.when_called { |_, options| options.use_config.should eq('foo') }
|
101
|
+
@command.run '--use-config', 'foo'
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should return true when present without an argument" do
|
105
|
+
@command.when_called { |_, options| options.use_config.should be_true }
|
106
|
+
@command.run '--use-config'
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should return nil when not present" do
|
110
|
+
@command.when_called { |_, options| options.use_config.should be_nil }
|
111
|
+
@command.run
|
112
|
+
end
|
104
113
|
end
|
105
|
-
|
114
|
+
|
115
|
+
describe "typed arguments" do
|
116
|
+
before do
|
117
|
+
@command.option '--interval N', Integer
|
118
|
+
end
|
119
|
+
|
120
|
+
it "should parse valid values" do
|
121
|
+
@command.when_called { |_, options| options.interval.should eq(5) }
|
122
|
+
@command.run '--interval', '5'
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should reject invalid values" do
|
126
|
+
lambda { @command.run '--interval', 'invalid' }.should raise_error(OptionParser::InvalidArgument)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
106
130
|
it "lists" do
|
107
131
|
@command.option '--fav COLORS', Array
|
108
132
|
@command.when_called { |_, options| options.fav.should eq(['red', 'green', 'blue']) }
|
data/spec/runner_spec.rb
CHANGED
@@ -493,5 +493,29 @@ describe Commander do
|
|
493
493
|
end.run!
|
494
494
|
end
|
495
495
|
end
|
496
|
-
|
496
|
+
|
497
|
+
describe "options with optional arguments" do
|
498
|
+
it "should return the argument when it is specified" do
|
499
|
+
new_command_runner 'foo', '--optional', 'arg1' do
|
500
|
+
command('foo') do |c|
|
501
|
+
c.option('--optional [argument]')
|
502
|
+
c.when_called do |_, options|
|
503
|
+
options.optional.should eq('arg1')
|
504
|
+
end
|
505
|
+
end
|
506
|
+
end.run!
|
507
|
+
end
|
508
|
+
|
509
|
+
it "should return true when no argument is specified for the option" do
|
510
|
+
new_command_runner 'foo', '--optional' do
|
511
|
+
command('foo') do |c|
|
512
|
+
c.option('--optional [argument]')
|
513
|
+
c.when_called do |_, options|
|
514
|
+
options.optional.should be_true
|
515
|
+
end
|
516
|
+
end
|
517
|
+
end.run!
|
518
|
+
end
|
519
|
+
end
|
520
|
+
|
497
521
|
end
|
data/spec/spec_helper.rb
CHANGED
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.0
|
4
|
+
version: 4.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,22 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-02-13 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: highline
|
17
|
-
requirement: &
|
17
|
+
requirement: &70213543949460 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.
|
22
|
+
version: 1.6.11
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70213543949460
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec
|
28
|
-
requirement: &
|
28
|
+
requirement: &70213543948960 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '2'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70213543948960
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rake
|
39
|
-
requirement: &
|
39
|
+
requirement: &70213543948580 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70213543948580
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: simplecov
|
50
|
-
requirement: &
|
50
|
+
requirement: &70213543948120 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70213543948120
|
59
59
|
description: The complete solution for Ruby command-line executables. Commander bridges
|
60
60
|
the gap between other terminal related libraries you know and love (OptionParser,
|
61
61
|
HighLine), while providing many new features, and an elegant API.
|