visionmedia-commander 2.4.2 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +4 -0
- data/Manifest +1 -0
- data/README.rdoc +8 -2
- data/Todo.rdoc +3 -4
- data/bin/commander +1 -1
- data/commander.gemspec +3 -3
- data/lib/commander/core_ext/string.rb +8 -11
- data/lib/commander/runner.rb +16 -11
- data/lib/commander/version.rb +1 -1
- data/spec/commander_spec.rb +20 -2
- data/spec/core_ext_spec.rb +9 -0
- metadata +3 -2
data/History.rdoc
CHANGED
data/Manifest
CHANGED
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
|
-
|
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
|
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
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.
|
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-
|
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
|
5
|
+
# Replace +hash+ keys with associated values. Mutative.
|
6
6
|
|
7
7
|
def tokenize! hash
|
8
|
-
hash.
|
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
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
data/lib/commander/runner.rb
CHANGED
@@ -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, "
|
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
|
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
|
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
|
data/lib/commander/version.rb
CHANGED
data/spec/commander_spec.rb
CHANGED
@@ -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
|
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.
|
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
|
+
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
|