visionmedia-commander 3.0.0 → 3.0.1
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.
- data/History.rdoc +5 -0
- data/README.rdoc +15 -7
- data/Todo.rdoc +3 -0
- data/commander.gemspec +1 -1
- data/lib/commander/command.rb +2 -2
- data/lib/commander/runner.rb +11 -2
- data/lib/commander/version.rb +1 -1
- data/spec/runner_spec.rb +5 -0
- metadata +1 -1
data/History.rdoc
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
|
2
|
+
=== 3.0.1 / 2009-03-12
|
3
|
+
|
4
|
+
* Fixed bug in #command_name_from_args preventing the left-most match for a command name to be used
|
5
|
+
* Fixed bug in Command#example preventing the formatter from outputting them correctly
|
6
|
+
|
2
7
|
=== 3.0.0 / 2009-03-12
|
3
8
|
|
4
9
|
* Added sub command help support when using the --help switch
|
data/README.rdoc
CHANGED
@@ -32,22 +32,30 @@ as well as an object, specifying a method to call, so view the RDoc for more inf
|
|
32
32
|
program :description, 'Stupid command that prints foo or bar.'
|
33
33
|
|
34
34
|
command :foo do |c|
|
35
|
-
c.syntax =
|
36
|
-
c.description =
|
35
|
+
c.syntax = 'foobar foo'
|
36
|
+
c.description = 'Displays foo'
|
37
37
|
c.when_called do |args, options|
|
38
|
-
say
|
38
|
+
say 'foo'
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
42
|
command :bar do |c|
|
43
|
-
c.syntax =
|
44
|
-
c.description =
|
45
|
-
c.option
|
43
|
+
c.syntax = 'foobar bar [options]'
|
44
|
+
c.description = 'Display bar with optional prefix and suffix'
|
45
|
+
c.option '--prefix STRING', String, 'Adds a prefix to bar'
|
46
|
+
c.option '--suffix STRING', String, 'Adds a suffix to bar'
|
46
47
|
c.when_called do |args, options|
|
47
|
-
|
48
|
+
options.default :prefix => '(', :suffix => ')'
|
49
|
+
say "#{options.prefix}bar#{options.suffix}"
|
48
50
|
end
|
49
51
|
end
|
50
52
|
|
53
|
+
$ foobar bar
|
54
|
+
# => (bar)
|
55
|
+
|
56
|
+
$ foobar bar --suffix '{' --prefix '}'
|
57
|
+
# => {bar}
|
58
|
+
|
51
59
|
== HighLine
|
52
60
|
|
53
61
|
As mentioned above the highline gem is imported into 'global scope', below
|
data/Todo.rdoc
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
|
2
2
|
== Major
|
3
3
|
|
4
|
+
* Fix help command ...
|
5
|
+
* Rough out some formatter specs using include?
|
4
6
|
* 1.9.x compatability
|
5
7
|
* Publish RDoc on mini page / screencasts
|
6
8
|
|
7
9
|
== Minor
|
8
10
|
|
11
|
+
* Add optional default command when none is present
|
9
12
|
* Fix multi-word command template creation via `commander init`
|
10
13
|
* Consider global #color method again
|
11
14
|
* Change; use stack technique for progress bar instead to clean things up
|
data/commander.gemspec
CHANGED
data/lib/commander/command.rb
CHANGED
@@ -41,7 +41,7 @@ module Commander
|
|
41
41
|
#
|
42
42
|
|
43
43
|
def example description, command
|
44
|
-
@examples
|
44
|
+
@examples << [description, command]
|
45
45
|
end
|
46
46
|
|
47
47
|
##
|
@@ -207,7 +207,7 @@ module Commander
|
|
207
207
|
|
208
208
|
def option_proc switches
|
209
209
|
Proc.new do |value|
|
210
|
-
@proxy_options
|
210
|
+
@proxy_options << [switch_to_sym(switches.last), value]
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
data/lib/commander/runner.rb
CHANGED
@@ -132,10 +132,19 @@ module Commander
|
|
132
132
|
|
133
133
|
##
|
134
134
|
# Attemps to locate a command name from within the arguments.
|
135
|
-
# Supports multi-word commands, using the largest possible match.
|
135
|
+
# Supports multi-word commands, using the largest left-most possible match.
|
136
136
|
|
137
137
|
def command_name_from_args
|
138
|
-
@__command_name_from_args ||=
|
138
|
+
@__command_name_from_args ||= begin
|
139
|
+
names = valid_command_names_from *@args.dup
|
140
|
+
if names.length > 1
|
141
|
+
names.first.length == names.last.length ?
|
142
|
+
names.first :
|
143
|
+
names.last
|
144
|
+
else
|
145
|
+
names.first
|
146
|
+
end
|
147
|
+
end
|
139
148
|
end
|
140
149
|
|
141
150
|
##
|
data/lib/commander/version.rb
CHANGED
data/spec/runner_spec.rb
CHANGED
@@ -101,6 +101,11 @@ describe Commander do
|
|
101
101
|
command('foo bar foo') {}
|
102
102
|
command_runner.command_name_from_args.should == 'foo bar foo'
|
103
103
|
end
|
104
|
+
|
105
|
+
it "should use the left-most command name when multiple are present" do
|
106
|
+
new_command_runner 'help', 'test'
|
107
|
+
command_runner.command_name_from_args.should == 'help'
|
108
|
+
end
|
104
109
|
end
|
105
110
|
|
106
111
|
describe "#active_command" do
|