visionmedia-commander 2.4.2 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ === 2.4.3 / 2009-01-15
3
+
4
+ * Fixed bug in command_name_from_args, preventing multi-word commands
5
+
2
6
  === 2.4.2 / 2009-01-12
3
7
 
4
8
  * Github! build me!
data/Manifest CHANGED
@@ -22,6 +22,7 @@ Manifest
22
22
  Rakefile
23
23
  README.rdoc
24
24
  spec/commander_spec.rb
25
+ spec/core_ext_spec.rb
25
26
  spec/help_formatter_spec.rb
26
27
  spec/spec_helper.rb
27
28
  tasks/docs.rake
data/README.rdoc CHANGED
@@ -57,12 +57,12 @@ are some quick examples for how to utilize highline in your command(s):
57
57
  ask("Password: ") { |q| q.echo = "*" }
58
58
 
59
59
  # Ask for password
60
- p ask("Password: ") { |q| q.echo = false }
60
+ ask("Password: ") { |q| q.echo = false }
61
61
 
62
62
  # Ask if the user agrees (yes or no)
63
63
  agree("Do something?")
64
64
 
65
- # Asks on a single line (note the space after ':'
65
+ # Asks on a single line (note the space after ':')
66
66
  ask("Name: ")
67
67
 
68
68
  # Asks with new line after "Description:"
@@ -148,6 +148,12 @@ methods directly.
148
148
  For feature rich ASCII tables for your terminal app check out visionmedia's terminal-table gem at
149
149
  http://github.com/visionmedia/terminal-table
150
150
 
151
+ +----------+-------+----+--------+-----------------------+
152
+ | Terminal | Table | Is | Wicked | Awesome |
153
+ +----------+-------+----+--------+-----------------------+
154
+ | | | | | get it while its hot! |
155
+ +----------+-------+----+--------+-----------------------+
156
+
151
157
  == Known Issues:
152
158
 
153
159
  * none
data/Todo.rdoc CHANGED
@@ -1,12 +1,11 @@
1
1
 
2
- * Release to RubyForge as well
3
- * Fix excessive Dir#[] calls due to rubygems, http://rubyforge.org/tracker/index.php?func=detail&aid=23170&group_id=126&atid=575
4
2
  * Change; Have VerboseFileUtils only output basename ?
3
+ * Change; refactor specs
4
+ * Release to RubyForge as well
5
5
  * Add highline paging ... clean it up
6
6
  * Add global options... change runner implementations as well as displaying in terminal formatter, OpenStruct inherit these options?
7
7
  * Add global --options switch for loading options from a filepath
8
8
  * Add; dynamically generate padding erb templates, command lists, multi-line text bodies etc
9
9
  * Add; display global options with global help
10
- * Change; consider reversing |options, args| so args can be |options, file, dir| etc.. adjust doc
11
- * Change; refactor specs
10
+ * Change; consider reversing |options, args| so args make use of ruby block param defaults |options, file, dir = SOME_DIR| etc.. adjust doc
12
11
  * Publish rdoc
data/bin/commander CHANGED
@@ -28,7 +28,7 @@ require '#{name}'
28
28
 
29
29
  program :name, '#{name}'
30
30
  program :version, #{name.camelcase}::VERSION::STRING
31
- program :description, '#{description}.'
31
+ program :description, '#{description}'
32
32
 
33
33
  CODE
34
34
  commands.each do |command|
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 = "2.4.2"
5
+ s.version = "2.4.3"
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-01-12}
9
+ s.date = %q{2009-01-15}
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
14
  s.extra_rdoc_files = ["bin/commander", "lib/commander/command.rb", "lib/commander/core_ext/array.rb", "lib/commander/core_ext/kernel.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/fileutils.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/import.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/kernel.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/fileutils.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/import.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "Manifest", "Rakefile", "README.rdoc", "spec/commander_spec.rb", "spec/help_formatter_spec.rb", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "test/fileutils.rb", "test/progress.rb", "test/ui.rb", "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/kernel.rb", "lib/commander/core_ext/object.rb", "lib/commander/core_ext/string.rb", "lib/commander/core_ext.rb", "lib/commander/fileutils.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/import.rb", "lib/commander/runner.rb", "lib/commander/user_interaction.rb", "lib/commander/version.rb", "lib/commander.rb", "Manifest", "Rakefile", "README.rdoc", "spec/commander_spec.rb", "spec/core_ext_spec.rb", "spec/help_formatter_spec.rb", "spec/spec_helper.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "test/fileutils.rb", "test/progress.rb", "test/ui.rb", "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"]
@@ -2,17 +2,14 @@
2
2
  class String
3
3
 
4
4
  ##
5
- # Replace _hash_ keys with associated values. Mutative.
5
+ # Replace +hash+ keys with associated values. Mutative.
6
6
 
7
7
  def tokenize! hash
8
- hash.each_pair do |k, v|
9
- self.gsub! Regexp.new(":#{k}"), v.to_s
10
- end
11
- self
8
+ hash.inject(self) { |s, (k, v)| s.gsub! /:#{k}/, v }
12
9
  end
13
10
 
14
11
  ##
15
- # Replace _hash_ keys with associated values.
12
+ # Replace +hash+ keys with associated values.
16
13
 
17
14
  def tokenize hash
18
15
  self.dup.tokenize! hash
@@ -23,11 +20,11 @@ class String
23
20
 
24
21
  def camelcase upcase_first_letter = true
25
22
  up = upcase_first_letter
26
- str = dup
27
- str.gsub!(/\/(.?)/){ "::#{$1.upcase}" }
28
- str.gsub!(/(?:_+|-+)([a-z])/){ $1.upcase }
29
- str.gsub!(/(\A|\s)([a-z])/){ $1 + $2.upcase } if up
30
- str
23
+ s = dup
24
+ s.gsub!(/\/(.?)/){ "::#{$1.upcase}" }
25
+ s.gsub!(/(?:_+|-+)([a-z])/){ $1.upcase }
26
+ s.gsub!(/(\A|\s)([a-z])/){ $1 + $2.upcase } if up
27
+ s
31
28
  end
32
29
 
33
30
  end
@@ -26,8 +26,7 @@ module Commander
26
26
 
27
27
  def initialize args = ARGV
28
28
  @args = args
29
- @commands, @options = {}, {}
30
- @program = {
29
+ @commands, @options, @program = {}, {}, {
31
30
  :help_formatter => Commander::HelpFormatter::Terminal,
32
31
  :int_message => "\nProcess interrupted",
33
32
  }
@@ -123,7 +122,7 @@ module Commander
123
122
  # Get a command object if available or nil.
124
123
 
125
124
  def get_command name
126
- @commands[name.to_s] or raise InvalidCommandError, "Invalid command '#{name || "nil"}'", caller
125
+ @commands[name.to_s] or raise InvalidCommandError, "invalid command '#{ name || 'nil' }'", caller
127
126
  end
128
127
 
129
128
  ##
@@ -150,9 +149,9 @@ module Commander
150
149
  # command names.
151
150
 
152
151
  def command_name_from_args
153
- @args.delete_switches.inject do |name, arg|
152
+ @_command_name_from_args ||= @args.delete_switches.inject do |name, arg|
154
153
  return name if command_exists? name
155
- name << " #{arg}"
154
+ name += " #{arg}"
156
155
  end
157
156
  end
158
157
 
@@ -162,7 +161,14 @@ module Commander
162
161
  def help_formatter
163
162
  @_help_formatter ||= @program[:help_formatter].new self
164
163
  end
165
-
164
+
165
+ ##
166
+ # Return arguments without the command name.
167
+
168
+ def args_without_command
169
+ @args.dup.join(' ').sub(command_name_from_args, '').split
170
+ end
171
+
166
172
  private
167
173
 
168
174
  ##
@@ -206,14 +212,13 @@ module Commander
206
212
  # Ignore invalid options since options will be further
207
213
  # parsed by our sub commands.
208
214
  end
215
+
216
+ ##
217
+ # Raises a CommandError when the program +key+ is not present, or is empty.
209
218
 
210
- def ensure_program_key_set key #:nodoc:
219
+ def ensure_program_key_set key
211
220
  raise CommandError, "Program #{key} required (use #program method)" if (@program[key].nil? || @program[key].empty?)
212
221
  end
213
222
 
214
- def args_without_command #:nodoc:
215
- @args.join(' ').sub(/^[\s]*#{active_command.name}/, '').split
216
- end
217
-
218
223
  end
219
224
  end
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Commander
3
3
  module VERSION #:nodoc:
4
- MAJOR, MINOR, TINY = [2, 4, 2]
4
+ MAJOR, MINOR, TINY = [2, 4, 3]
5
5
  STRING = [MAJOR, MINOR, TINY].join '.'
6
6
  end
7
7
  end
@@ -210,14 +210,32 @@ describe Commander do
210
210
  it "should allow multi-word strings as command names to be called correctly" do
211
211
  arguments = nil
212
212
  options = nil
213
- new_command_runner 'foo', 'bar', 'i', 'like', '--i-like', 'cookies', 'bar'
214
- command 'foo bar' do |c|
213
+ new_command_runner 'foo', 'bar', 'something', 'i', 'like', '--i-like', 'cookies', 'bar'
214
+ command 'foo bar something' do |c|
215
215
  c.option '--i-like WHAT'
216
216
  c.when_called { |args, opts| arguments, options = args, opts }
217
217
  end
218
+ command_runner.command_name_from_args.should eql('foo bar something')
219
+ command_runner.args_without_command.should eql(['i', 'like', '--i-like', 'cookies', 'bar'])
218
220
  command_runner.run!
219
221
  arguments.should eql(['i', 'like', 'bar'])
220
222
  options.i_like.should eql('cookies')
221
223
  end
224
+
225
+ it "should allow multi-word strings as command names to be called correctly, with options before command name" do
226
+ arguments = nil
227
+ options = nil
228
+ new_command_runner '--something', 'foo', 'bar', 'random_arg'
229
+ command 'foo bar' do |c|
230
+ c.option '--something'
231
+ c.when_called { |args, opts| arguments, options = args, opts }
232
+ end
233
+ command_runner.command_name_from_args.should eql('foo bar')
234
+ command_runner.args_without_command.should eql(['--something', 'random_arg'])
235
+ command_runner.run!
236
+ arguments.should eql(['random_arg'])
237
+ options.something.should be_true
238
+ end
239
+
222
240
 
223
241
  end
@@ -0,0 +1,9 @@
1
+
2
+ describe Commander do
3
+ describe String do
4
+ it "should tokenize strings" do
5
+ s = 'Welcome :name, enjoy your :object'.tokenize!({ :name => 'TJ', :object => 'cookie' })
6
+ s.should == 'Welcome TJ, enjoy your cookie'
7
+ end
8
+ end
9
+ 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: 2.4.2
4
+ version: 2.4.3
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-01-12 00:00:00 -08:00
12
+ date: 2009-01-15 00:00:00 -08:00
13
13
  default_executable: commander
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -84,6 +84,7 @@ files:
84
84
  - Rakefile
85
85
  - README.rdoc
86
86
  - spec/commander_spec.rb
87
+ - spec/core_ext_spec.rb
87
88
  - spec/help_formatter_spec.rb
88
89
  - spec/spec_helper.rb
89
90
  - tasks/docs.rake