visionmedia-commander 3.0.1 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +5 -0
- data/Manifest +2 -1
- data/Todo.rdoc +0 -2
- data/commander.gemspec +2 -2
- data/lib/commander/runner.rb +4 -13
- data/lib/commander/version.rb +1 -1
- data/spec/{help_formatter_spec.rb → help_formatters/base_spec.rb} +0 -0
- data/spec/help_formatters/terminal_spec.rb +66 -0
- metadata +3 -2
data/History.rdoc
CHANGED
data/Manifest
CHANGED
@@ -22,7 +22,8 @@ spec/command_spec.rb
|
|
22
22
|
spec/core_ext/array_spec.rb
|
23
23
|
spec/core_ext/object_spec.rb
|
24
24
|
spec/core_ext/string_spec.rb
|
25
|
-
spec/
|
25
|
+
spec/help_formatters/base_spec.rb
|
26
|
+
spec/help_formatters/terminal_spec.rb
|
26
27
|
spec/runner_spec.rb
|
27
28
|
spec/spec_helper.rb
|
28
29
|
tasks/docs.rake
|
data/Todo.rdoc
CHANGED
data/commander.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{commander}
|
5
|
-
s.version = "3.0.
|
5
|
+
s.version = "3.0.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk"]
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = %q{tj@vision-media.ca}
|
13
13
|
s.executables = ["commander"]
|
14
14
|
s.extra_rdoc_files = ["bin/commander", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "README.rdoc", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
15
|
-
s.files = ["bin/commander", "commander.gemspec", "History.rdoc", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "Manifest", "Rakefile", "README.rdoc", "spec/command_spec.rb", "spec/core_ext/array_spec.rb", "spec/core_ext/object_spec.rb", "spec/core_ext/string_spec.rb", "spec/
|
15
|
+
s.files = ["bin/commander", "commander.gemspec", "History.rdoc", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "Manifest", "Rakefile", "README.rdoc", "spec/command_spec.rb", "spec/core_ext/array_spec.rb", "spec/core_ext/object_spec.rb", "spec/core_ext/string_spec.rb", "spec/help_formatters/base_spec.rb", "spec/help_formatters/terminal_spec.rb", "spec/runner_spec.rb", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "test/pbar", "test/ui", "Todo.rdoc"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/visionmedia/commander}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Commander", "--main", "README.rdoc"]
|
data/lib/commander/runner.rb
CHANGED
@@ -39,7 +39,7 @@ module Commander
|
|
39
39
|
require_program :name, :version, :description
|
40
40
|
case
|
41
41
|
when options[:version] ; $terminal.say "#{program(:name)} #{program(:version)}"
|
42
|
-
when options[:help] ; command(:help).run(*@args[1
|
42
|
+
when options[:help] ; command(:help).run(*@args[1..-1])
|
43
43
|
else active_command.run *args_without_command_name
|
44
44
|
end
|
45
45
|
rescue InvalidCommandError
|
@@ -132,19 +132,10 @@ 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
|
135
|
+
# Supports multi-word commands, using the largest possible match.
|
136
136
|
|
137
137
|
def command_name_from_args
|
138
|
-
@__command_name_from_args ||=
|
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
|
138
|
+
@__command_name_from_args ||= valid_command_names_from(*@args.dup).sort.last
|
148
139
|
end
|
149
140
|
|
150
141
|
##
|
@@ -152,7 +143,7 @@ module Commander
|
|
152
143
|
|
153
144
|
def valid_command_names_from *args
|
154
145
|
arg_string = args.delete_switches.join ' '
|
155
|
-
commands.keys.
|
146
|
+
commands.keys.find_all { |name| name if /^#{name}/.match arg_string }
|
156
147
|
end
|
157
148
|
|
158
149
|
##
|
data/lib/commander/version.rb
CHANGED
File without changes
|
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
describe Commander::HelpFormatter::Terminal do
|
3
|
+
|
4
|
+
before :each do
|
5
|
+
mock_terminal
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "global help" do
|
9
|
+
before :each do
|
10
|
+
new_command_runner 'help' do
|
11
|
+
command :'install gem' do |c|
|
12
|
+
c.syntax = 'foo install gem [options]'
|
13
|
+
c.summary = 'Install some gem'
|
14
|
+
end
|
15
|
+
end.run!
|
16
|
+
@global_help = @output.string
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "should display" do
|
20
|
+
it "the sub-command name" do
|
21
|
+
@global_help.should include('install gem')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "the summary" do
|
25
|
+
@global_help.should include('Install some gem')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "sub-command help" do
|
31
|
+
before :each do
|
32
|
+
new_command_runner 'help', 'install', 'gem' do
|
33
|
+
command :'install gem' do |c|
|
34
|
+
c.syntax = 'foo install gem [options]'
|
35
|
+
c.summary = 'Install some gem'
|
36
|
+
c.description = 'Install some gem, blah blah blah'
|
37
|
+
c.example 'one', 'two'
|
38
|
+
c.example 'three', 'four'
|
39
|
+
end
|
40
|
+
end.run!
|
41
|
+
@command_help = @output.string
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "should display" do
|
45
|
+
it "the sub-command name" do
|
46
|
+
@command_help.should include('install gem')
|
47
|
+
end
|
48
|
+
|
49
|
+
it "the description" do
|
50
|
+
@command_help.should include('Install some gem, blah blah blah')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "all examples" do
|
54
|
+
@command_help.should include('# one')
|
55
|
+
@command_help.should include('two')
|
56
|
+
@command_help.should include('# three')
|
57
|
+
@command_help.should include('four')
|
58
|
+
end
|
59
|
+
|
60
|
+
it "the syntax" do
|
61
|
+
@command_help.should include('foo install gem [options]')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visionmedia-commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TJ Holowaychuk
|
@@ -73,7 +73,8 @@ files:
|
|
73
73
|
- spec/core_ext/array_spec.rb
|
74
74
|
- spec/core_ext/object_spec.rb
|
75
75
|
- spec/core_ext/string_spec.rb
|
76
|
-
- spec/
|
76
|
+
- spec/help_formatters/base_spec.rb
|
77
|
+
- spec/help_formatters/terminal_spec.rb
|
77
78
|
- spec/runner_spec.rb
|
78
79
|
- spec/spec_helper.rb
|
79
80
|
- tasks/docs.rake
|