commander 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +6 -0
- data/commander.gemspec +2 -2
- data/lib/commander/runner.rb +4 -1
- data/lib/commander/user_interaction.rb +7 -2
- data/lib/commander/version.rb +1 -1
- data/spec/runner_spec.rb +1 -1
- data/spec/ui_spec.rb +13 -1
- metadata +2 -2
data/History.rdoc
CHANGED
data/commander.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{commander}
|
5
|
-
s.version = "4.0.
|
5
|
+
s.version = "4.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"]
|
9
|
-
s.date = %q{2010-01-
|
9
|
+
s.date = %q{2010-01-19}
|
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}
|
data/lib/commander/runner.rb
CHANGED
@@ -51,6 +51,7 @@ module Commander
|
|
51
51
|
trace = false
|
52
52
|
require_program :version, :description
|
53
53
|
trap('INT') { abort program(:int_message) } if program(:int_message)
|
54
|
+
trap('INT') { program(:int_block).call } if program(:int_block)
|
54
55
|
global_option('-h', '--help', 'Display help documentation') { command(:help).run *@args[1..-1]; return }
|
55
56
|
global_option('-v', '--version', 'Display version information') { say version; return }
|
56
57
|
global_option('-t', '--trace', 'Display backtrace when an error occurs') { trace = true }
|
@@ -109,12 +110,14 @@ module Commander
|
|
109
110
|
# :int_message Message to display when interrupted (CTRL + C)
|
110
111
|
#
|
111
112
|
|
112
|
-
def program key, *args
|
113
|
+
def program key, *args, &block
|
113
114
|
if key == :help and !args.empty?
|
114
115
|
@program[:help] ||= {}
|
115
116
|
@program[:help][args.first] = args.at(1)
|
116
117
|
elsif key == :help_formatter && !args.empty?
|
117
118
|
@program[key] = (@help_formatter_aliases[args.first] || args.first)
|
119
|
+
elsif block
|
120
|
+
@program[key] = block
|
118
121
|
else
|
119
122
|
@program[key] = *args unless args.empty?
|
120
123
|
@program[key]
|
@@ -223,6 +223,7 @@ module Commander
|
|
223
223
|
|
224
224
|
def progress arr, options = {}, &block
|
225
225
|
bar = ProgressBar.new arr.length, options
|
226
|
+
bar.show
|
226
227
|
arr.each { |v| bar.increment yield(v) }
|
227
228
|
end
|
228
229
|
|
@@ -325,7 +326,11 @@ module Commander
|
|
325
326
|
# Completion percentage.
|
326
327
|
|
327
328
|
def percent_complete
|
328
|
-
|
329
|
+
if @total_steps.zero?
|
330
|
+
100
|
331
|
+
else
|
332
|
+
@step * 100 / @total_steps
|
333
|
+
end
|
329
334
|
end
|
330
335
|
|
331
336
|
##
|
@@ -368,7 +373,7 @@ module Commander
|
|
368
373
|
:steps_remaining => steps_remaining,
|
369
374
|
:total_steps => @total_steps,
|
370
375
|
:time_elapsed => "%0.2fs" % time_elapsed,
|
371
|
-
:time_remaining => "%0.2fs" % time_remaining,
|
376
|
+
:time_remaining => @step > 0 ? "%0.2fs" % time_remaining : '',
|
372
377
|
}.
|
373
378
|
merge! @tokens
|
374
379
|
end
|
data/lib/commander/version.rb
CHANGED
data/spec/runner_spec.rb
CHANGED
@@ -189,7 +189,7 @@ describe Commander do
|
|
189
189
|
it "should return array of valid command names" do
|
190
190
|
command('foo bar') {}
|
191
191
|
command('foo bar foo') {}
|
192
|
-
command_runner.valid_command_names_from('foo', 'bar', 'foo').should == ['foo bar', 'foo bar foo']
|
192
|
+
command_runner.valid_command_names_from('foo', 'bar', 'foo').sort.should == ['foo bar', 'foo bar foo']
|
193
193
|
end
|
194
194
|
|
195
195
|
it "should return empty array when no possible command names exist" do
|
data/spec/ui_spec.rb
CHANGED
@@ -10,4 +10,16 @@ describe Commander::UI do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
|
13
|
+
describe "progress" do
|
14
|
+
it "should not die on an empty list" do
|
15
|
+
exception = false
|
16
|
+
begin
|
17
|
+
progress([]) {}
|
18
|
+
rescue
|
19
|
+
exception = true
|
20
|
+
end
|
21
|
+
exception.should_not be_true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
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.
|
4
|
+
version: 4.0.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: 2010-01-
|
12
|
+
date: 2010-01-19 00:00:00 -08:00
|
13
13
|
default_executable: commander
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|