visionmedia-commander 3.2.0 → 3.2.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,13 @@
1
1
 
2
+ === 3.2.2 / 2009-04-01
3
+
4
+ * Github's gem builder timed out ? ...
5
+
6
+ === 3.2.1 / 2009-04-01
7
+
8
+ * Added Commander::HelpFormatter::TerminalCompact
9
+ * Fix; updated gemspec / manifest removing test/* causing issue [#26]
10
+
2
11
  === 3.2.0 / 2009-03-26
3
12
 
4
13
  * Added implied small switches so they appear in help (-h, -v, etc)
data/Manifest CHANGED
@@ -11,6 +11,9 @@ lib/commander/help_formatters/base.rb
11
11
  lib/commander/help_formatters/terminal/command_help.erb
12
12
  lib/commander/help_formatters/terminal/help.erb
13
13
  lib/commander/help_formatters/terminal.rb
14
+ lib/commander/help_formatters/terminal_compact/command_help.erb
15
+ lib/commander/help_formatters/terminal_compact/help.erb
16
+ lib/commander/help_formatters/terminal_compact.rb
14
17
  lib/commander/help_formatters.rb
15
18
  lib/commander/runner.rb
16
19
  lib/commander/user_interaction.rb
@@ -30,7 +33,3 @@ spec/spec_helper.rb
30
33
  tasks/docs.rake
31
34
  tasks/gemspec.rake
32
35
  tasks/spec.rake
33
- test/foo
34
- test/pbar
35
- test/re
36
- test/ui
data/README.rdoc CHANGED
@@ -12,11 +12,15 @@ features, and an elegant API.
12
12
  * Parses options using OptionParser
13
13
  * Auto-populates struct with options ( no more { |v| options[:recursive] = v } )
14
14
  * Auto-generates help documentation via pluggable help formatters
15
+ * Packaged with two help formatters (Terminal, TerminalCompact)
15
16
  * Imports the highline gem for interacting with the terminal
16
17
  * Adds additional user interaction functionality
17
18
  * Highly customizable progress bar with intuative, simple usage
18
19
  * Multi-word command name support such as 'drupal module install MOD', rather than 'drupal module_install MOD'
19
20
  * Use the 'commander' executable to initialize a commander driven program
21
+ * Optional default sub-command when none is present
22
+ * Global / Sub-command level options
23
+ * Sub-command aliasing (very powerful, as both switches and arguments can be used)
20
24
 
21
25
  == Example
22
26
 
@@ -239,11 +243,21 @@ You may:
239
243
  say 'foo' if options.verbose
240
244
  ...
241
245
 
246
+ === Formatters
247
+
248
+ Two core formatters are currently available, the default Terminal formatter as well
249
+ as TerminalCompact. To utilize a different formatter simply use :help_formatter like below:
250
+
251
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
252
+
253
+ This abstraction could be utilized to generate HTML documentation for your executable.
254
+
242
255
  == Tips
243
256
 
244
257
  When adding a global or sub-command option, OptionParser implicitly adds a small
245
258
  switch even when not explicitly created, for example -c will be the same as --config
246
- in both examples:
259
+ in both examples, however '-c' will only appear in the documentation when explicitly
260
+ assigning it.
247
261
 
248
262
  global_option '-c', '--config FILE'
249
263
  global_option '--config FILE'
data/commander.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{commander}
5
- s.version = "3.2.0"
5
+ s.version = "3.2.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"]
9
- s.date = %q{2009-03-26}
9
+ s.date = %q{2009-04-01}
10
10
  s.default_executable = %q{commander}
11
11
  s.description = %q{The complete solution for Ruby command-line executables}
12
12
  s.email = %q{tj@vision-media.ca}
13
13
  s.executables = ["commander"]
14
- s.extra_rdoc_files = ["bin/commander", "lib/commander/blank.rb", "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/blank.rb", "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/foo", "test/pbar", "test/re", "test/ui"]
14
+ s.extra_rdoc_files = ["bin/commander", "lib/commander/blank.rb", "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/terminal_compact/command_help.erb", "lib/commander/help_formatters/terminal_compact/help.erb", "lib/commander/help_formatters/terminal_compact.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/blank.rb", "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/terminal_compact/command_help.erb", "lib/commander/help_formatters/terminal_compact/help.erb", "lib/commander/help_formatters/terminal_compact.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"]
16
16
  s.has_rdoc = true
17
17
  s.homepage = %q{http://visionmedia.github.com/commander}
18
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Commander", "--main", "README.rdoc"]
@@ -4,5 +4,6 @@ require 'commander/help_formatters/base'
4
4
  module Commander
5
5
  module HelpFormatter
6
6
  autoload :Terminal, 'commander/help_formatters/terminal'
7
+ autoload :TerminalCompact, 'commander/help_formatters/terminal_compact'
7
8
  end
8
9
  end
@@ -1,6 +1,4 @@
1
1
 
2
- require 'erb'
3
-
4
2
  module Commander
5
3
  module HelpFormatter
6
4
  class Terminal < Base
@@ -13,7 +11,7 @@ module Commander
13
11
  end
14
12
 
15
13
  def template name
16
- ERB.new(File.read(File.expand_path(File.dirname(__FILE__)) + "/terminal/#{name}.erb"), nil, '-')
14
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal', "#{name}.erb")), nil, '-')
17
15
  end
18
16
  end
19
17
  end
@@ -17,7 +17,7 @@
17
17
  <% unless @examples.empty? -%>
18
18
 
19
19
  <%= $terminal.color "EXAMPLES", :bold %>:
20
- <% @examples.each do |description, command| -%>
20
+ <% for description, command in @examples -%>
21
21
 
22
22
  # <%= description %>
23
23
  <%= command %>
@@ -26,7 +26,7 @@
26
26
  <% unless @options.empty? -%>
27
27
 
28
28
  <%= $terminal.color "OPTIONS", :bold %>:
29
- <% @options.each do |option| -%>
29
+ <% for option in @options -%>
30
30
 
31
31
  <%= option[:switches].join ', ' %>
32
32
  <%= option[:description] %>
@@ -8,27 +8,27 @@
8
8
  <%= program :description %>
9
9
 
10
10
  <%= $terminal.color "SUB-COMMANDS", :bold %>:
11
- <% @commands.each_pair do |name, command| -%>
11
+ <% for name, command in @commands -%>
12
12
  <% unless alias? name %>
13
13
  <%= "%-20s %s" % [command.name, command.summary || command.description] -%>
14
14
  <% end -%>
15
15
  <% end %>
16
16
  <% unless @aliases.empty? %>
17
17
  <%= $terminal.color "ALIASES", :bold %>:
18
- <% @aliases.each do |alias_name, args| %>
18
+ <% for alias_name, args in @aliases %>
19
19
  <%= "%-20s %s %s" % [alias_name, command(alias_name).name, args.join(' ')] -%>
20
20
  <% end %>
21
21
  <% end %>
22
22
  <% unless @options.empty? -%>
23
23
  <%= $terminal.color "GLOBAL OPTIONS", :bold %>:
24
- <% @options.each do |option| -%>
24
+ <% for option in @options -%>
25
25
 
26
26
  <%= option[:switches].join ', ' %>
27
27
  <%= option[:description] %>
28
28
  <% end -%>
29
29
  <% end -%>
30
30
  <% if program :help -%>
31
- <% program(:help).each_pair do |title, body| %>
31
+ <% for title, body in program(:help) %>
32
32
  <%= $terminal.color title.to_s.upcase, :bold %>:
33
33
 
34
34
  <%= body %>
@@ -0,0 +1,12 @@
1
+
2
+ require 'erb'
3
+
4
+ module Commander
5
+ module HelpFormatter
6
+ class TerminalCompact < Terminal
7
+ def template name
8
+ ERB.new(File.read(File.join(File.dirname(__FILE__), 'terminal_compact', "#{name}.erb")), nil, '-')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,27 @@
1
+
2
+ <%= @name %>
3
+ <% if @description || @summary -%>
4
+
5
+ <%= @description || @summary %>
6
+ <% end -%>
7
+ <% if @syntax -%>
8
+
9
+ Usage: <%= @syntax %>
10
+ <% end -%>
11
+ <% unless @examples.empty? -%>
12
+
13
+ Examples:
14
+ <% for description, command in @examples -%>
15
+
16
+ # <%= description %>
17
+ <%= command %>
18
+ <% end -%>
19
+ <% end -%>
20
+ <% unless @options.empty? -%>
21
+
22
+ Options:
23
+ <% for option in @options -%>
24
+ <%= "%-20s %s" % [option[:switches].join(', '), option[:description]] %>
25
+ <% end -%>
26
+ <% end -%>
27
+
@@ -0,0 +1,30 @@
1
+
2
+ <%= program :name %>
3
+
4
+ <%= program :description %>
5
+
6
+ Sub-Commands:
7
+ <% for name, command in @commands -%>
8
+ <% unless alias? name -%>
9
+ <%= "%-20s %s" % [command.name, command.summary || command.description] %>
10
+ <% end -%>
11
+ <% end -%>
12
+ <% unless @aliases.empty? %>
13
+ Aliases:
14
+ <% for alias_name, args in @aliases -%>
15
+ <%= "%-20s %s %s" % [alias_name, command(alias_name).name, args.join(' ')] %>
16
+ <% end -%>
17
+ <% end %>
18
+ <% unless @options.empty? -%>
19
+ Global Options:
20
+ <% for option in @options -%>
21
+ <%= "%-20s %s" % [option[:switches].join(', '), option[:description]] -%>
22
+ <% end -%>
23
+ <% end -%>
24
+ <% if program :help -%>
25
+ <% for title, body in program(:help) %>
26
+ <%= title %>:
27
+ <%= body %>
28
+ <% end %>
29
+ <% end -%>
30
+
@@ -98,9 +98,9 @@ module Commander
98
98
  #
99
99
  # === Keys:
100
100
  #
101
- # :name (required) Program name
102
101
  # :version (required) Program version triple, ex: '0.0.1'
103
102
  # :description (required) Program description
103
+ # :name Program name, defaults to basename of executable
104
104
  # :help_formatter Defaults to Commander::HelpFormatter::Terminal
105
105
  # :help Allows addition of arbitrary global help blocks
106
106
  # :int_message Message to display when interrupted (CTRL + C)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Commander
3
- VERSION = '3.2.0'
3
+ VERSION = '3.2.2'
4
4
  end
data/spec/runner_spec.rb CHANGED
@@ -277,27 +277,27 @@ describe Commander do
277
277
  end
278
278
 
279
279
  it "when using multi-word commands" do
280
- new_command_runner '--trace', 'my', 'command', 'something', 'foo', 'bar' do
281
- command('my command') {}
280
+ new_command_runner '--verbose', 'my', 'command', 'something', 'foo', 'bar' do
281
+ command('my command') { |c| c.option('--verbose') }
282
282
  command_runner.command_name_from_args.should == 'my command'
283
- command_runner.args_without_command_name.should == ['--trace', 'something', 'foo', 'bar']
283
+ command_runner.args_without_command_name.should == ['--verbose', 'something', 'foo', 'bar']
284
284
  end.run!
285
285
  end
286
286
 
287
287
  it "when using multi-word commands with parts of the command name as arguments" do
288
- new_command_runner '--trace', 'my', 'command', 'something', 'my', 'command' do
289
- command('my command') {}
288
+ new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
289
+ command('my command') { |c| c.option('--verbose') }
290
290
  command_runner.command_name_from_args.should == 'my command'
291
- command_runner.args_without_command_name.should == ['--trace', 'something', 'my', 'command']
291
+ command_runner.args_without_command_name.should == ['--verbose', 'something', 'my', 'command']
292
292
  end.run!
293
293
  end
294
294
 
295
295
  it "when using multi-word commands with other commands using the same words" do
296
- new_command_runner '--trace', 'my', 'command', 'something', 'my', 'command' do
296
+ new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
297
297
  command('my command') {}
298
- command('my command something') {}
298
+ command('my command something') { |c| c.option('--verbose') }
299
299
  command_runner.command_name_from_args.should == 'my command something'
300
- command_runner.args_without_command_name.should == ['--trace', 'my', 'command']
300
+ command_runner.args_without_command_name.should == ['--verbose', 'my', 'command']
301
301
  end.run!
302
302
  end
303
303
  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.2.0
4
+ version: 3.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-26 00:00:00 -07:00
12
+ date: 2009-04-01 00:00:00 -07:00
13
13
  default_executable: commander
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,6 +40,9 @@ extra_rdoc_files:
40
40
  - lib/commander/help_formatters/terminal/command_help.erb
41
41
  - lib/commander/help_formatters/terminal/help.erb
42
42
  - lib/commander/help_formatters/terminal.rb
43
+ - lib/commander/help_formatters/terminal_compact/command_help.erb
44
+ - lib/commander/help_formatters/terminal_compact/help.erb
45
+ - lib/commander/help_formatters/terminal_compact.rb
43
46
  - lib/commander/help_formatters.rb
44
47
  - lib/commander/runner.rb
45
48
  - lib/commander/user_interaction.rb
@@ -63,6 +66,9 @@ files:
63
66
  - lib/commander/help_formatters/terminal/command_help.erb
64
67
  - lib/commander/help_formatters/terminal/help.erb
65
68
  - lib/commander/help_formatters/terminal.rb
69
+ - lib/commander/help_formatters/terminal_compact/command_help.erb
70
+ - lib/commander/help_formatters/terminal_compact/help.erb
71
+ - lib/commander/help_formatters/terminal_compact.rb
66
72
  - lib/commander/help_formatters.rb
67
73
  - lib/commander/runner.rb
68
74
  - lib/commander/user_interaction.rb
@@ -82,10 +88,6 @@ files:
82
88
  - tasks/docs.rake
83
89
  - tasks/gemspec.rake
84
90
  - tasks/spec.rake
85
- - test/foo
86
- - test/pbar
87
- - test/re
88
- - test/ui
89
91
  has_rdoc: true
90
92
  homepage: http://visionmedia.github.com/commander
91
93
  post_install_message: