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 CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ === 3.0.2 / 2009-03-12
3
+
4
+ * Added terminal formatter specs
5
+ * Fixed bug preventing command names passed to help from working
6
+
2
7
  === 3.0.1 / 2009-03-12
3
8
 
4
9
  * Fixed bug in #command_name_from_args preventing the left-most match for a command name to be used
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/help_formatter_spec.rb
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
@@ -1,8 +1,6 @@
1
1
 
2
2
  == Major
3
3
 
4
- * Fix help command ...
5
- * Rough out some formatter specs using include?
6
4
  * 1.9.x compatability
7
5
  * Publish RDoc on mini page / screencasts
8
6
 
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.1"
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/help_formatter_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"]
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"]
@@ -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..@args.length])
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 left-most possible match.
135
+ # Supports multi-word commands, using the largest possible match.
136
136
 
137
137
  def 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
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.map { |key| key if arg_string.include? key }.compact
146
+ commands.keys.find_all { |name| name if /^#{name}/.match arg_string }
156
147
  end
157
148
 
158
149
  ##
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Commander
3
- VERSION = '3.0.1'
3
+ VERSION = '3.0.2'
4
4
  end
@@ -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.1
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/help_formatter_spec.rb
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