commander 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
6
+ coverage/*
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
data/DEVELOPMENT CHANGED
@@ -1,23 +1,15 @@
1
- To run the development rake tasks, you need rake and echoe gems installed.
2
-
3
- To install the rest of the development dependencies:
4
-
5
- $ rake dev_setup
1
+ To run the development rake tasks, you need bundler installed.
6
2
 
7
3
  Before you push any changes, run the RSpec suite:
8
4
 
9
5
  $ rake spec
10
6
 
11
- Build the docs:
12
-
13
- $ rake docs
14
-
15
- Build and check the docs:
16
-
17
- $ rake docs:open
18
-
19
7
  To build a new version of the gem:
20
8
 
21
9
  $ rake build
22
- $ rake gem
23
10
 
11
+ To push the new version to Rubygems:
12
+
13
+ $ rake release
14
+
15
+ (http://rubygems.org/gems/commander)
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/History.rdoc CHANGED
@@ -1,3 +1,10 @@
1
+ 4.0.7 / 2012-01-23
2
+ ==================
3
+
4
+ * Improved support for JRuby and Windows (and any other platforms that don't support Kernel.fork).
5
+ * Fixed bug #33 - support `--help` after commands.
6
+ * Reorganized help output to display synopsis before description (issue #12).
7
+
1
8
  4.0.6 / 2011-09-15
2
9
  ==================
3
10
 
data/README.rdoc CHANGED
@@ -202,7 +202,7 @@ growlnotify can also be installed via homebrew[http://mxcl.github.com/homebrew/]
202
202
  === Option Defaults
203
203
 
204
204
  The options struct passed to #action provides a #default method, allowing you
205
- to set defaults in a clean manor to options which have not been set.
205
+ to set defaults in a clean manner for options which have not been set.
206
206
 
207
207
  command :foo do |c|
208
208
  c.option '--interval SECONDS', Integer, 'Interval in seconds'
data/Rakefile CHANGED
@@ -1,34 +1,10 @@
1
- $:.unshift 'lib'
1
+ require "rspec/core/rake_task"
2
+ require "bundler/gem_tasks"
2
3
 
3
- require 'psych' if RUBY_VERSION >= "1.9.2"
4
- require 'rubygems'
5
-
6
- load_errors = ['highline', 'echoe'].map do |g|
7
- begin
8
- require g
9
- nil
10
- rescue LoadError
11
- "The #{g} gem is not installed. Please run:\n\tgem install #{g}"
12
- end
13
- end.compact
14
- abort "Missing dependencies!\n" + load_errors.join("\n") unless load_errors.empty?
15
-
16
- require 'commander'
17
- require 'rake'
18
-
19
- Echoe.new "commander", Commander::VERSION do |p|
20
- p.email = "ggilder@tractionco.com"
21
- p.summary = "The complete solution for Ruby command-line executables"
22
- p.url = "http://visionmedia.github.com/commander"
23
- p.runtime_dependencies << "highline ~>1.5.0"
24
- p.development_dependencies << "echoe ~>4.0.0"
25
- p.development_dependencies << "sdoc ~>0.3.11"
26
- p.development_dependencies << "rspec <2"
27
-
28
- p.eval = Proc.new do
29
- self.authors = ["TJ Holowaychuk", "Gabriel Gilder"]
30
- self.default_executable = "commander"
31
- end
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.verbose = false
7
+ t.rspec_opts = '--color'
32
8
  end
33
9
 
34
- Dir['tasks/**/*.rake'].sort.each { |lib| load lib }
10
+ task :default => :spec
data/bin/commander CHANGED
@@ -8,17 +8,17 @@ program :version, Commander::VERSION
8
8
  program :description, 'Commander utility program.'
9
9
 
10
10
  command :init do |c|
11
- c.syntax = 'commander init <file>'
12
- c.summary = 'Initialize a commander template'
13
- c.description = 'Initialize an empty <file> with a commander template,
11
+ c.syntax = 'commander init <file>'
12
+ c.summary = 'Initialize a commander template'
13
+ c.description = 'Initialize an empty <file> with a commander template,
14
14
  allowing very quick creation of commander executables.'
15
- c.example 'Create a new file with a commander template.', 'commander init bin/my_executable'
16
- c.action do |args, options|
17
- file = args.shift || abort('file argument required.')
18
- name = ask 'Machine name of program: '
19
- description = ask 'Describe your program: '
20
- commands = ask_for_array 'List the commands you wish to create: '
21
- begin
15
+ c.example 'Create a new file with a commander template.', 'commander init bin/my_executable'
16
+ c.action do |args, options|
17
+ file = args.shift || abort('file argument required.')
18
+ name = ask 'Machine name of program: '
19
+ description = ask 'Describe your program: '
20
+ commands = ask_for_array 'List the commands you wish to create: '
21
+ begin
22
22
  File.open(file, 'w') do |f|
23
23
  f.write <<-"...".gsub!(/^ {10}/, '')
24
24
  #!/usr/bin/env ruby
@@ -48,8 +48,8 @@ command :init do |c|
48
48
  end
49
49
  end
50
50
  say "Initialized template in #{file}"
51
- rescue Exception => e
51
+ rescue Exception => e
52
52
  abort e
53
- end
54
- end
53
+ end
54
+ end
55
55
  end
data/commander.gemspec CHANGED
@@ -1,42 +1,25 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "commander/version"
2
4
 
3
5
  Gem::Specification.new do |s|
4
- s.name = "commander"
5
- s.version = "4.0.6"
6
+ s.name = "commander"
7
+ s.version = Commander::VERSION
8
+ s.authors = ["TJ Holowaychuk", "Gabriel Gilder"]
9
+ s.email = ["ggilder@tractionco.com"]
10
+ s.homepage = "http://visionmedia.github.com/commander"
11
+ s.summary = "The complete solution for Ruby command-line executables"
12
+ s.description = "The complete solution for Ruby command-line executables. Commander bridges the gap between other terminal related libraries you know and love (OptionParser, HighLine), while providing many new features, and an elegant API."
6
13
 
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["TJ Holowaychuk", "Gabriel Gilder"]
9
- s.date = "2011-09-15"
10
- s.description = "The complete solution for Ruby command-line executables"
11
- s.email = "ggilder@tractionco.com"
12
- s.executables = ["commander"]
13
- s.extra_rdoc_files = ["README.rdoc", "bin/commander", "lib/commander.rb", "lib/commander/blank.rb", "lib/commander/command.rb", "lib/commander/core_ext.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/object.rb", "lib/commander/delegates.rb", "lib/commander/help_formatters.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal_compact.rb", "lib/commander/help_formatters/terminal_compact/command_help.erb", "lib/commander/help_formatters/terminal_compact/help.erb", "lib/commander/import.rb", "lib/commander/platform.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "tasks/dev_setup.rake", "tasks/docs.rake", "tasks/gemspec.rake"]
14
- s.files = ["DEVELOPMENT", "History.rdoc", "Manifest", "README.rdoc", "Rakefile", "bin/commander", "commander.gemspec", "lib/commander.rb", "lib/commander/blank.rb", "lib/commander/command.rb", "lib/commander/core_ext.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/object.rb", "lib/commander/delegates.rb", "lib/commander/help_formatters.rb", "lib/commander/help_formatters/base.rb", "lib/commander/help_formatters/terminal.rb", "lib/commander/help_formatters/terminal/command_help.erb", "lib/commander/help_formatters/terminal/help.erb", "lib/commander/help_formatters/terminal_compact.rb", "lib/commander/help_formatters/terminal_compact/command_help.erb", "lib/commander/help_formatters/terminal_compact/help.erb", "lib/commander/import.rb", "lib/commander/platform.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "spec/command_spec.rb", "spec/core_ext/array_spec.rb", "spec/core_ext/object_spec.rb", "spec/help_formatters/terminal_spec.rb", "spec/runner_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/ui_spec.rb", "tasks/dev_setup.rake", "tasks/docs.rake", "tasks/gemspec.rake"]
15
- s.homepage = "http://visionmedia.github.com/commander"
16
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Commander", "--main", "README.rdoc"]
17
- s.require_paths = ["lib"]
18
14
  s.rubyforge_project = "commander"
19
- s.rubygems_version = "1.8.10"
20
- s.summary = "The complete solution for Ruby command-line executables"
21
15
 
22
- if s.respond_to? :specification_version then
23
- s.specification_version = 3
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
24
20
 
25
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- s.add_runtime_dependency(%q<highline>, ["~> 1.5.0"])
27
- s.add_development_dependency(%q<echoe>, ["~> 4.0.0"])
28
- s.add_development_dependency(%q<sdoc>, ["~> 0.3.11"])
29
- s.add_development_dependency(%q<rspec>, ["< 2"])
30
- else
31
- s.add_dependency(%q<highline>, ["~> 1.5.0"])
32
- s.add_dependency(%q<echoe>, ["~> 4.0.0"])
33
- s.add_dependency(%q<sdoc>, ["~> 0.3.11"])
34
- s.add_dependency(%q<rspec>, ["< 2"])
35
- end
36
- else
37
- s.add_dependency(%q<highline>, ["~> 1.5.0"])
38
- s.add_dependency(%q<echoe>, ["~> 4.0.0"])
39
- s.add_dependency(%q<sdoc>, ["~> 0.3.11"])
40
- s.add_dependency(%q<rspec>, ["< 2"])
41
- end
21
+ s.add_runtime_dependency("highline", "~> 1.5.0")
22
+ s.add_development_dependency("rspec", "~> 2")
23
+ s.add_development_dependency("rake")
24
+ s.add_development_dependency("simplecov")
42
25
  end
@@ -2,11 +2,6 @@
2
2
  <%= $terminal.color "NAME", :bold %>:
3
3
 
4
4
  <%= @name %>
5
-
6
- <%= $terminal.color "DESCRIPTION", :bold %>:
7
-
8
- <%= @description || @summary || 'No description.' -%>
9
-
10
5
  <% if @syntax -%>
11
6
 
12
7
  <%= $terminal.color "SYNOPSIS", :bold %>:
@@ -14,6 +9,11 @@
14
9
  <%= @syntax -%>
15
10
 
16
11
  <% end -%>
12
+
13
+ <%= $terminal.color "DESCRIPTION", :bold %>:
14
+
15
+ <%= @description || @summary || 'No description.' -%>
16
+
17
17
  <% unless @examples.empty? -%>
18
18
 
19
19
  <%= $terminal.color "EXAMPLES", :bold %>:
@@ -1,13 +1,13 @@
1
1
 
2
2
  <%= @name %>
3
- <% if @description || @summary -%>
4
-
5
- <%= @description || @summary %>
6
- <% end -%>
7
3
  <% if @syntax -%>
8
4
 
9
5
  Usage: <%= @syntax %>
10
6
  <% end -%>
7
+ <% if @description || @summary -%>
8
+
9
+ <%= @description || @summary %>
10
+ <% end -%>
11
11
  <% unless @examples.empty? -%>
12
12
 
13
13
  Examples:
@@ -52,7 +52,11 @@ module Commander
52
52
  require_program :version, :description
53
53
  trap('INT') { abort program(:int_message) } if program(:int_message)
54
54
  trap('INT') { program(:int_block).call } if program(:int_block)
55
- global_option('-h', '--help', 'Display help documentation') { command(:help).run *@args[1..-1]; return }
55
+ global_option('-h', '--help', 'Display help documentation') do
56
+ args = @args - %w[-h --help]
57
+ command(:help).run(*args)
58
+ return
59
+ end
56
60
  global_option('-v', '--version', 'Display version information') { say version; return }
57
61
  global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true }
58
62
  parse_global_options
@@ -271,7 +275,11 @@ module Commander
271
275
  say help_formatter.render
272
276
  else
273
277
  command = command args.join(' ')
274
- require_valid_command command
278
+ begin
279
+ require_valid_command command
280
+ rescue InvalidCommandError => e
281
+ abort "#{e}. Use --help for more information"
282
+ end
275
283
  say help_formatter.render_command(command)
276
284
  end
277
285
  end
@@ -252,22 +252,32 @@ module Commander
252
252
 
253
253
  def enable_paging
254
254
  return unless $stdout.tty?
255
- return if Platform::jruby? # Fork is not supported by JRuby
255
+ return unless Process.respond_to? :fork
256
256
  read, write = IO.pipe
257
257
 
258
+ # Kernel.fork is not supported on all platforms and configurations.
259
+ # As of Ruby 1.9, `Process.respond_to? :fork` should return false on
260
+ # configurations that don't support it, but versions before 1.9 don't
261
+ # seem to do this reliably and instead raise a NotImplementedError
262
+ # (which is rescued below).
263
+
258
264
  if Kernel.fork
259
265
  $stdin.reopen read
260
- read.close; write.close
266
+ write.close; read.close
261
267
  Kernel.select [$stdin]
262
268
  ENV['LESS'] = 'FSRX'
263
269
  pager = ENV['PAGER'] || 'less'
264
270
  exec pager rescue exec '/bin/sh', '-c', pager
265
271
  else
272
+ # subprocess
266
273
  $stdout.reopen write
267
274
  $stderr.reopen write if $stderr.tty?
268
- read.close; write.close
269
- return
275
+ write.close; read.close
270
276
  end
277
+ rescue NotImplementedError
278
+ ensure
279
+ write.close if write && !write.closed?
280
+ read.close if read && !read.closed?
271
281
  end
272
282
 
273
283
  ##
@@ -1,4 +1,3 @@
1
-
2
1
  module Commander
3
- VERSION = '4.0.6'
2
+ VERSION = '4.0.7'
4
3
  end
data/spec/command_spec.rb CHANGED
@@ -15,13 +15,13 @@ describe Commander::Command do
15
15
  it "should act like an open struct" do
16
16
  @options.send = 'mail'
17
17
  @options.call = true
18
- @options.send.should == 'mail'
19
- @options.call.should == true
18
+ @options.send.should eq('mail')
19
+ @options.call.should eq(true)
20
20
  end
21
21
 
22
22
  it "should allow __send__ to function as always" do
23
23
  @options.send = 'foo'
24
- @options.__send__(:send).should == 'foo'
24
+ @options.__send__(:send).should eq('foo')
25
25
  end
26
26
  end
27
27
 
@@ -37,7 +37,7 @@ describe Commander::Command do
37
37
 
38
38
  it "should allow usage of common method names" do
39
39
  @command.option '--open file'
40
- @command.when_called { |_, options| options.open.should == 'foo' }
40
+ @command.when_called { |_, options| options.open.should eq('foo') }
41
41
  @command.run '--open', 'foo'
42
42
  end
43
43
  end
@@ -45,7 +45,7 @@ describe Commander::Command do
45
45
  describe "#run" do
46
46
  describe "should invoke #when_called" do
47
47
  it "with arguments seperated from options" do
48
- @command.when_called { |args, options| args.join(' ').should == 'just some args' }
48
+ @command.when_called { |args, options| args.join(' ').should eq('just some args') }
49
49
  @command.run '--verbose', 'just', 'some', 'args'
50
50
  end
51
51
 
@@ -86,32 +86,32 @@ describe Commander::Command do
86
86
 
87
87
  it "mandatory arguments" do
88
88
  @command.option '--file FILE'
89
- @command.when_called { |_, options| options.file.should == 'foo' }
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
92
  end
93
93
 
94
94
  it "optional arguments" do
95
95
  @command.option '--use-config [file] '
96
- @command.when_called { |_, options| options.use_config.should == 'foo' }
96
+ @command.when_called { |_, options| options.use_config.should eq('foo') }
97
97
  @command.run '--use-config', 'foo'
98
98
  @command.when_called { |_, options| options.use_config.should be_nil }
99
99
  @command.run '--use-config'
100
100
  @command.option '--interval N', Integer
101
- @command.when_called { |_, options| options.interval.should == 5 }
101
+ @command.when_called { |_, options| options.interval.should eq(5) }
102
102
  @command.run '--interval', '5'
103
103
  lambda { @command.run '--interval', 'invalid' }.should raise_error(OptionParser::InvalidArgument)
104
104
  end
105
105
 
106
106
  it "lists" do
107
107
  @command.option '--fav COLORS', Array
108
- @command.when_called { |_, options| options.fav.should == ['red', 'green', 'blue'] }
108
+ @command.when_called { |_, options| options.fav.should eq(['red', 'green', 'blue']) }
109
109
  @command.run '--fav', 'red,green,blue'
110
110
  end
111
111
 
112
112
  it "lists with multi-word items" do
113
113
  @command.option '--fav MOVIES', Array
114
- @command.when_called { |_, options| options.fav.should == ['super\ bad', 'nightmare'] }
114
+ @command.when_called { |_, options| options.fav.should eq(['super\ bad', 'nightmare']) }
115
115
  @command.run '--fav', 'super\ bad,nightmare'
116
116
  end
117
117
 
@@ -122,8 +122,8 @@ describe Commander::Command do
122
122
  options.default \
123
123
  :files => ['foo', 'bar'],
124
124
  :interval => 5
125
- options.files.should == ['foo', 'bar']
126
- options.interval.should == 15
125
+ options.files.should eq(['foo', 'bar'])
126
+ options.interval.should eq(15)
127
127
  end
128
128
  @command.run '--interval', '15'
129
129
  end
@@ -4,11 +4,11 @@ describe Array do
4
4
 
5
5
  describe "#parse" do
6
6
  it "should seperate a list of words into an array" do
7
- Array.parse('just a test').should == ['just', 'a', 'test']
7
+ Array.parse('just a test').should eq(['just', 'a', 'test'])
8
8
  end
9
9
 
10
10
  it "should preserve escaped whitespace" do
11
- Array.parse('just a\ test').should == ['just', 'a test']
11
+ Array.parse('just a\ test').should eq(['just', 'a test'])
12
12
  end
13
13
  end
14
14
 
data/spec/runner_spec.rb CHANGED
@@ -6,34 +6,34 @@ describe Commander do
6
6
  mock_terminal
7
7
  create_test_command
8
8
  end
9
-
9
+
10
10
  describe "#program" do
11
11
  it "should set / get program information" do
12
12
  program :name, 'test'
13
- program(:name).should == 'test'
13
+ program(:name).should eq('test')
14
14
  end
15
15
 
16
16
  it "should allow arbitrary blocks of global help documentation" do
17
17
  program :help, 'Copyright', 'TJ Holowaychuk'
18
- program(:help)['Copyright'].should == 'TJ Holowaychuk'
18
+ program(:help)['Copyright'].should eq('TJ Holowaychuk')
19
19
  end
20
20
 
21
21
  it "should raise an error when required info has not been set" do
22
22
  new_command_runner '--help'
23
- program :version, ''
23
+ program :version, ''
24
24
  lambda { run! }.should raise_error(Commander::Runner::CommandError)
25
25
  end
26
26
 
27
27
  it "should allow aliases of help formatters" do
28
28
  program :help_formatter, :compact
29
- program(:help_formatter).should == Commander::HelpFormatter::TerminalCompact
29
+ program(:help_formatter).should eq(Commander::HelpFormatter::TerminalCompact)
30
30
  end
31
31
  end
32
32
 
33
33
  describe "#command" do
34
- it "should return a command instance when only the name is passed" do
35
- command(:test).should be_instance_of(Commander::Command)
36
- end
34
+ it "should return a command instance when only the name is passed" do
35
+ command(:test).should be_instance_of(Commander::Command)
36
+ end
37
37
 
38
38
  it "should return nil when the command does not exist" do
39
39
  command(:im_not_real).should be_nil
@@ -43,26 +43,26 @@ describe Commander do
43
43
  describe "#separate_switches_from_description" do
44
44
  it "should seperate switches and description returning both" do
45
45
  switches, description = *Commander::Runner.separate_switches_from_description('-h', '--help', 'display help')
46
- switches.should == ['-h', '--help']
47
- description.should == 'display help'
46
+ switches.should eq(['-h', '--help'])
47
+ description.should eq('display help')
48
48
  end
49
49
  end
50
50
 
51
51
  describe "#switch_to_sym" do
52
52
  it "should return a symbol based on the switch name" do
53
- Commander::Runner.switch_to_sym('--trace').should == :trace
54
- Commander::Runner.switch_to_sym('--foo-bar').should == :foo_bar
55
- Commander::Runner.switch_to_sym('--[no-]feature"').should == :feature
56
- Commander::Runner.switch_to_sym('--[no-]feature ARG').should == :feature
57
- Commander::Runner.switch_to_sym('--file [ARG]').should == :file
58
- Commander::Runner.switch_to_sym('--colors colors').should == :colors
53
+ Commander::Runner.switch_to_sym('--trace').should eq(:trace)
54
+ Commander::Runner.switch_to_sym('--foo-bar').should eq(:foo_bar)
55
+ Commander::Runner.switch_to_sym('--[no-]feature"').should eq(:feature)
56
+ Commander::Runner.switch_to_sym('--[no-]feature ARG').should eq(:feature)
57
+ Commander::Runner.switch_to_sym('--file [ARG]').should eq(:file)
58
+ Commander::Runner.switch_to_sym('--colors colors').should eq(:colors)
59
59
  end
60
60
  end
61
61
 
62
62
  describe "#alias_command" do
63
63
  it "should alias a command" do
64
64
  alias_command :foo, :test
65
- command(:foo).should == command(:test)
65
+ command(:foo).should eq(command(:test))
66
66
  end
67
67
 
68
68
  it "should pass arguments passed to the alias when called" do
@@ -74,7 +74,7 @@ describe Commander do
74
74
  end
75
75
  alias_command :'install gem', :install, '--gem-name'
76
76
  end.run!
77
- gem_name.should == 'commander'
77
+ gem_name.should eq('commander')
78
78
  end
79
79
  end
80
80
 
@@ -84,7 +84,7 @@ describe Commander do
84
84
  new_command_runner 'test', '--config', 'foo' do
85
85
  global_option('--config FILE') { |f| file = f }
86
86
  end.run!
87
- file.should == 'foo'
87
+ file.should eq('foo')
88
88
  end
89
89
 
90
90
  it "should be inherited by commands" do
@@ -120,7 +120,7 @@ describe Commander do
120
120
  c.when_called {}
121
121
  end
122
122
  end.run!
123
- global_option.should == 'MAGIC'
123
+ global_option.should eq('MAGIC')
124
124
  end
125
125
 
126
126
  it 'should parse global options after command' do
@@ -132,7 +132,7 @@ describe Commander do
132
132
  c.when_called {}
133
133
  end
134
134
  end.run!
135
- global_option.should == 'MAGIC'
135
+ global_option.should eq('MAGIC')
136
136
  end
137
137
 
138
138
  it 'should parse global options placed before command options' do
@@ -146,7 +146,7 @@ describe Commander do
146
146
  end
147
147
  end.run!
148
148
 
149
- global_option.should == 'MAGIC'
149
+ global_option.should eq('MAGIC')
150
150
  end
151
151
 
152
152
  it 'should parse global options placed after command options' do
@@ -160,7 +160,7 @@ describe Commander do
160
160
  end
161
161
  end.run!
162
162
 
163
- global_option.should == 'MAGIC'
163
+ global_option.should eq('MAGIC')
164
164
  end
165
165
 
166
166
  it 'should parse global options surrounded by command options' do
@@ -175,7 +175,7 @@ describe Commander do
175
175
  end
176
176
  end.run!
177
177
 
178
- global_option.should == 'MAGIC'
178
+ global_option.should eq('MAGIC')
179
179
  end
180
180
 
181
181
  it 'should not parse command options' do
@@ -191,7 +191,7 @@ describe Commander do
191
191
  end.parse_global_options
192
192
 
193
193
  command_option.should be_nil
194
- global_option.should == 'MAGIC'
194
+ global_option.should eq('MAGIC')
195
195
  end
196
196
 
197
197
  it 'should not affect command arguments with values' do
@@ -206,8 +206,8 @@ describe Commander do
206
206
  end
207
207
  end.run!
208
208
 
209
- command_option.should == 'bar'
210
- global_option.should == 'MAGIC'
209
+ command_option.should eq('bar')
210
+ global_option.should eq('MAGIC')
211
211
  end
212
212
 
213
213
  it 'should not affect global arguments with values' do
@@ -221,7 +221,7 @@ describe Commander do
221
221
  end
222
222
  end.run!
223
223
 
224
- global_option.should == 'bar'
224
+ global_option.should eq('bar')
225
225
  end
226
226
 
227
227
  it 'should allow global arguments with values before command arguments (github issue #8)' do
@@ -236,8 +236,8 @@ describe Commander do
236
236
  end
237
237
  end.run!
238
238
 
239
- global_option.should == 'path'
240
- command_option.should == 'bar'
239
+ global_option.should eq('path')
240
+ command_option.should eq('bar')
241
241
  end
242
242
  end
243
243
 
@@ -254,7 +254,7 @@ describe Commander do
254
254
  args << '--command-with-arg' << 'rawr'
255
255
  args << '--paths' << '"lib/**/*.js","spec/**/*.js"'
256
256
  command_runner.remove_global_options options, args
257
- args.should == ['--command', '--command-with-arg', 'rawr']
257
+ args.should eq(['--command', '--command-with-arg', 'rawr'])
258
258
  end
259
259
 
260
260
  it "should not swallow an argument unless it expects an argument" do
@@ -267,7 +267,7 @@ describe Commander do
267
267
  args << '-a' << 'deleted'
268
268
  args << 'beta'
269
269
  command_runner.remove_global_options options, args
270
- args.should == ['alpha', 'beta']
270
+ args.should eq(['alpha', 'beta'])
271
271
  end
272
272
  end
273
273
 
@@ -292,7 +292,7 @@ describe Commander do
292
292
 
293
293
  describe "--version" do
294
294
  it "should output program version" do
295
- run('--version').should == "test 1.2.3\n"
295
+ run('--version').should eq("test 1.2.3\n")
296
296
  end
297
297
  end
298
298
 
@@ -300,6 +300,10 @@ describe Commander do
300
300
  it "should not output an invalid command message" do
301
301
  run('--help').should_not == "invalid command. Use --help for more information\n"
302
302
  end
303
+
304
+ it "can be used before or after the command and options" do
305
+ run('test', '--help').should eq("Implement help for test here\n")
306
+ end
303
307
  end
304
308
 
305
309
  describe "with invalid options" do
@@ -329,40 +333,58 @@ describe Commander do
329
333
  end
330
334
  end
331
335
 
336
+ describe "with invalid command passed to --help" do
337
+ it "should output an invalid command message" do
338
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
339
+ lambda {
340
+ run('--help', 'does_not_exist')
341
+ }.should raise_error(SystemExit, /invalid command. Use --help for more information/)
342
+ end
343
+ end
344
+
345
+ describe "with invalid option passed to --help" do
346
+ it "should output an invalid option message" do
347
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
348
+ lambda {
349
+ run('--help', 'test', '--invalid-option')
350
+ }.should raise_error(SystemExit, /invalid option: --invalid-option/)
351
+ end
352
+ end
353
+
332
354
  describe "#valid_command_names_from" do
333
355
  it "should return array of valid command names" do
334
356
  command('foo bar') {}
335
- command('foo bar foo') {}
336
- command_runner.valid_command_names_from('foo', 'bar', 'foo').sort.should == ['foo bar', 'foo bar foo']
357
+ command('foo bar foo') {}
358
+ command_runner.valid_command_names_from('foo', 'bar', 'foo').sort.should eq(['foo bar', 'foo bar foo'])
337
359
  end
338
360
 
339
361
  it "should return empty array when no possible command names exist" do
340
- command_runner.valid_command_names_from('fake', 'command', 'name').should == []
362
+ command_runner.valid_command_names_from('fake', 'command', 'name').should eq([])
341
363
  end
342
364
  end
343
365
 
344
366
  describe "#command_name_from_args" do
345
367
  it "should locate command within arbitrary arguments passed" do
346
- new_command_runner '--help', '--arbitrary', 'test'
347
- command_runner.command_name_from_args.should == 'test'
368
+ new_command_runner '--help', '--arbitrary', 'test'
369
+ command_runner.command_name_from_args.should eq('test')
348
370
  end
349
371
 
350
372
  it "should support multi-word commands" do
351
- new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
352
- command('some long command') {}
353
- command_runner.command_name_from_args.should == 'some long command'
373
+ new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
374
+ command('some long command') {}
375
+ command_runner.command_name_from_args.should eq('some long command')
354
376
  end
355
377
 
356
378
  it "should match the longest possible command" do
357
- new_command_runner '--help', '--arbitrary', 'foo', 'bar', 'foo'
358
- command('foo bar') {}
359
- command('foo bar foo') {}
360
- command_runner.command_name_from_args.should == 'foo bar foo'
379
+ new_command_runner '--help', '--arbitrary', 'foo', 'bar', 'foo'
380
+ command('foo bar') {}
381
+ command('foo bar foo') {}
382
+ command_runner.command_name_from_args.should eq('foo bar foo' )
361
383
  end
362
384
 
363
385
  it "should use the left-most command name when multiple are present" do
364
- new_command_runner 'help', 'test'
365
- command_runner.command_name_from_args.should == 'help'
386
+ new_command_runner 'help', 'test'
387
+ command_runner.command_name_from_args.should eq('help' )
366
388
  end
367
389
  end
368
390
 
@@ -388,7 +410,7 @@ describe Commander do
388
410
  new_command_runner '--trace' do
389
411
  default_command :test
390
412
  command(:test).should_receive(:run).once
391
- command_runner.active_command.should == command(:test)
413
+ command_runner.active_command.should eq(command(:test))
392
414
  end.run!
393
415
  end
394
416
 
@@ -397,7 +419,7 @@ describe Commander do
397
419
  default_command :test
398
420
  command(:'foo bar'){}
399
421
  command(:'foo bar').should_receive(:run).once
400
- command_runner.active_command.should == command(:'foo bar')
422
+ command_runner.active_command.should eq(command(:'foo bar'))
401
423
  end.run!
402
424
  end
403
425
 
@@ -406,7 +428,7 @@ describe Commander do
406
428
  default_command :'foo bar'
407
429
  command(:'foo bar'){}
408
430
  command(:'foo bar something'){}
409
- command_runner.active_command.should == command(:'foo bar something')
431
+ command_runner.active_command.should eq(command(:'foo bar something'))
410
432
  end
411
433
 
412
434
  it "should allow defaulting of command aliases" do
@@ -422,7 +444,7 @@ describe Commander do
422
444
  it "when options are passed before the command name" do
423
445
  new_command_runner '--verbose', 'test', 'foo', 'bar' do
424
446
  @command.when_called do |args, options|
425
- args.should == ['foo', 'bar']
447
+ args.should eq(['foo', 'bar'])
426
448
  options.verbose.should be_true
427
449
  end
428
450
  end.run!
@@ -431,7 +453,7 @@ describe Commander do
431
453
  it "when options are passed after the command name" do
432
454
  new_command_runner 'test', '--verbose', 'foo', 'bar' do
433
455
  @command.when_called do |args, options|
434
- args.should == ['foo', 'bar']
456
+ args.should eq(['foo', 'bar'])
435
457
  options.verbose.should be_true
436
458
  end
437
459
  end.run!
@@ -440,7 +462,7 @@ describe Commander do
440
462
  it "when an argument passed is the same name as the command" do
441
463
  new_command_runner 'test', '--verbose', 'foo', 'test', 'bar' do
442
464
  @command.when_called do |args, options|
443
- args.should == ['foo', 'test', 'bar']
465
+ args.should eq(['foo', 'test', 'bar'])
444
466
  options.verbose.should be_true
445
467
  end
446
468
  end.run!
@@ -449,16 +471,16 @@ describe Commander do
449
471
  it "when using multi-word commands" do
450
472
  new_command_runner '--verbose', 'my', 'command', 'something', 'foo', 'bar' do
451
473
  command('my command') { |c| c.option('--verbose') }
452
- command_runner.command_name_from_args.should == 'my command'
453
- command_runner.args_without_command_name.should == ['--verbose', 'something', 'foo', 'bar']
474
+ command_runner.command_name_from_args.should eq('my command')
475
+ command_runner.args_without_command_name.should eq(['--verbose', 'something', 'foo', 'bar'])
454
476
  end.run!
455
477
  end
456
478
 
457
479
  it "when using multi-word commands with parts of the command name as arguments" do
458
480
  new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
459
481
  command('my command') { |c| c.option('--verbose') }
460
- command_runner.command_name_from_args.should == 'my command'
461
- command_runner.args_without_command_name.should == ['--verbose', 'something', 'my', 'command']
482
+ command_runner.command_name_from_args.should eq('my command')
483
+ command_runner.args_without_command_name.should eq(['--verbose', 'something', 'my', 'command'])
462
484
  end.run!
463
485
  end
464
486
 
@@ -466,8 +488,8 @@ describe Commander do
466
488
  new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
467
489
  command('my command') {}
468
490
  command('my command something') { |c| c.option('--verbose') }
469
- command_runner.command_name_from_args.should == 'my command something'
470
- command_runner.args_without_command_name.should == ['--verbose', 'my', 'command']
491
+ command_runner.command_name_from_args.should eq('my command something')
492
+ command_runner.args_without_command_name.should eq(['--verbose', 'my', 'command'])
471
493
  end.run!
472
494
  end
473
495
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
+ require 'rubygems'
2
+ require 'simplecov'
3
+ SimpleCov.start
1
4
 
2
5
  $:.unshift File.dirname(__FILE__) + '/../lib'
3
- require 'rubygems'
4
6
  require 'commander/import'
5
7
  require 'stringio'
6
8
 
@@ -47,7 +49,7 @@ def command_runner
47
49
  end
48
50
 
49
51
  def run *args
50
- new_command_runner *args do
52
+ new_command_runner(*args) do
51
53
  program :help_formatter, Commander::HelpFormatter::Base
52
54
  end.run!
53
55
  @output.string
data/spec/ui_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Commander::UI do
5
5
  describe ".replace_tokens" do
6
6
  it "should replace tokens within a string, with hash values" do
7
7
  result = Commander::UI.replace_tokens 'Welcome :name, enjoy your :object'.freeze, :name => 'TJ', :object => 'cookie'
8
- result.should == 'Welcome TJ, enjoy your cookie'
8
+ result.should eq('Welcome TJ, enjoy your cookie')
9
9
  end
10
10
  end
11
11
 
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.6
4
+ version: 4.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-09-15 00:00:00.000000000Z
13
+ date: 2012-01-23 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: highline
17
- requirement: &2155737700 !ruby/object:Gem::Requirement
17
+ requirement: &70326274634880 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,73 +22,54 @@ dependencies:
22
22
  version: 1.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2155737700
25
+ version_requirements: *70326274634880
26
26
  - !ruby/object:Gem::Dependency
27
- name: echoe
28
- requirement: &2155737200 !ruby/object:Gem::Requirement
27
+ name: rspec
28
+ requirement: &70326274634380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.0
33
+ version: '2'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2155737200
36
+ version_requirements: *70326274634380
37
37
  - !ruby/object:Gem::Dependency
38
- name: sdoc
39
- requirement: &2155736700 !ruby/object:Gem::Requirement
38
+ name: rake
39
+ requirement: &70326274634000 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
- - - ~>
42
+ - - ! '>='
43
43
  - !ruby/object:Gem::Version
44
- version: 0.3.11
44
+ version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2155736700
47
+ version_requirements: *70326274634000
48
48
  - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &2155736200 !ruby/object:Gem::Requirement
49
+ name: simplecov
50
+ requirement: &70326274633540 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
- - - <
53
+ - - ! '>='
54
54
  - !ruby/object:Gem::Version
55
- version: '2'
55
+ version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2155736200
59
- description: The complete solution for Ruby command-line executables
60
- email: ggilder@tractionco.com
58
+ version_requirements: *70326274633540
59
+ description: The complete solution for Ruby command-line executables. Commander bridges
60
+ the gap between other terminal related libraries you know and love (OptionParser,
61
+ HighLine), while providing many new features, and an elegant API.
62
+ email:
63
+ - ggilder@tractionco.com
61
64
  executables:
62
65
  - commander
63
66
  extensions: []
64
- extra_rdoc_files:
65
- - README.rdoc
66
- - bin/commander
67
- - lib/commander.rb
68
- - lib/commander/blank.rb
69
- - lib/commander/command.rb
70
- - lib/commander/core_ext.rb
71
- - lib/commander/core_ext/array.rb
72
- - lib/commander/core_ext/object.rb
73
- - lib/commander/delegates.rb
74
- - lib/commander/help_formatters.rb
75
- - lib/commander/help_formatters/base.rb
76
- - lib/commander/help_formatters/terminal.rb
77
- - lib/commander/help_formatters/terminal/command_help.erb
78
- - lib/commander/help_formatters/terminal/help.erb
79
- - lib/commander/help_formatters/terminal_compact.rb
80
- - lib/commander/help_formatters/terminal_compact/command_help.erb
81
- - lib/commander/help_formatters/terminal_compact/help.erb
82
- - lib/commander/import.rb
83
- - lib/commander/platform.rb
84
- - lib/commander/runner.rb
85
- - lib/commander/user_interaction.rb
86
- - lib/commander/version.rb
87
- - tasks/dev_setup.rake
88
- - tasks/docs.rake
89
- - tasks/gemspec.rake
67
+ extra_rdoc_files: []
90
68
  files:
69
+ - .gitignore
70
+ - .travis.yml
91
71
  - DEVELOPMENT
72
+ - Gemfile
92
73
  - History.rdoc
93
74
  - Manifest
94
75
  - README.rdoc
@@ -120,22 +101,12 @@ files:
120
101
  - spec/core_ext/object_spec.rb
121
102
  - spec/help_formatters/terminal_spec.rb
122
103
  - spec/runner_spec.rb
123
- - spec/spec.opts
124
104
  - spec/spec_helper.rb
125
105
  - spec/ui_spec.rb
126
- - tasks/dev_setup.rake
127
- - tasks/docs.rake
128
- - tasks/gemspec.rake
129
106
  homepage: http://visionmedia.github.com/commander
130
107
  licenses: []
131
108
  post_install_message:
132
- rdoc_options:
133
- - --line-numbers
134
- - --inline-source
135
- - --title
136
- - Commander
137
- - --main
138
- - README.rdoc
109
+ rdoc_options: []
139
110
  require_paths:
140
111
  - lib
141
112
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -149,11 +120,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
120
  requirements:
150
121
  - - ! '>='
151
122
  - !ruby/object:Gem::Version
152
- version: '1.2'
123
+ version: '0'
153
124
  requirements: []
154
125
  rubyforge_project: commander
155
- rubygems_version: 1.8.10
126
+ rubygems_version: 1.8.12
156
127
  signing_key:
157
128
  specification_version: 3
158
129
  summary: The complete solution for Ruby command-line executables
159
- test_files: []
130
+ test_files:
131
+ - spec/command_spec.rb
132
+ - spec/core_ext/array_spec.rb
133
+ - spec/core_ext/object_spec.rb
134
+ - spec/help_formatters/terminal_spec.rb
135
+ - spec/runner_spec.rb
136
+ - spec/spec_helper.rb
137
+ - spec/ui_spec.rb
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color
data/tasks/dev_setup.rake DELETED
@@ -1,11 +0,0 @@
1
- desc 'Install development dependencies'
2
- task :dev_setup do
3
- ObjectSpace.each_object(Echoe) do |o|
4
- o.development_dependencies.each do |gem_string|
5
- gem_name, version = gem_string.split(' ', 2)
6
- cmd = "gem install #{gem_name}"
7
- cmd += " --version '#{version}'" if (version)
8
- puts `#{cmd}`
9
- end
10
- end
11
- end
data/tasks/docs.rake DELETED
@@ -1,19 +0,0 @@
1
-
2
- desc 'Build docs with sdoc gem'
3
- task :docs do
4
- require "sdoc"
5
- sh 'sdoc -N lib/commander'
6
- end
7
-
8
- namespace :docs do
9
-
10
- desc 'Remove rdoc products'
11
- task :remove => [:clobber_docs]
12
-
13
- desc 'Build docs, and open in browser for viewing (specify BROWSER)'
14
- task :open => [:docs] do
15
- browser = ENV["BROWSER"] || "safari"
16
- sh "open -a #{browser} doc/index.html"
17
- end
18
-
19
- end
data/tasks/gemspec.rake DELETED
@@ -1,3 +0,0 @@
1
-
2
- desc 'Build gemspec file'
3
- task :gemspec => [:build_gemspec]