gli 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -18,6 +18,11 @@ module GLI
|
|
18
18
|
self.name.to_s <=> other.name.to_s
|
19
19
|
end
|
20
20
|
|
21
|
+
# Array of the name and aliases, as string
|
22
|
+
def names_and_aliases
|
23
|
+
[self.name,self.aliases].flatten.compact.map(&:to_s)
|
24
|
+
end
|
25
|
+
|
21
26
|
private
|
22
27
|
# Returns a string of all possible forms
|
23
28
|
# of this flag. Mostly intended for printing
|
@@ -67,8 +67,7 @@ COMMANDS
|
|
67
67
|
sub.flags.merge(sub.switches)
|
68
68
|
end
|
69
69
|
usage << sub_options.map { |option_name,option|
|
70
|
-
|
71
|
-
all_names.map { |_|
|
70
|
+
option.names_and_aliases.map { |_|
|
72
71
|
CommandLineOption.name_as_string(_,false) + (option.kind_of?(Flag) ? " #{option.argument_name }" : '')
|
73
72
|
}.join('|')
|
74
73
|
}.map { |_| "[#{_}]" }.sort.join(' ')
|
@@ -37,8 +37,12 @@ module GLI
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def set_defaults(options_by_name,options_hash)
|
40
|
-
options_by_name.each do |
|
41
|
-
|
40
|
+
options_by_name.values.each do |option|
|
41
|
+
option.names_and_aliases.each do |option_name|
|
42
|
+
[option_name,option_name.to_sym].each do |name|
|
43
|
+
options_hash[name] = option.default_value if options_hash[name].nil?
|
44
|
+
end
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -53,7 +57,7 @@ module GLI
|
|
53
57
|
def self.setup_options(opts,tokens,options)
|
54
58
|
tokens.each do |ignore,token|
|
55
59
|
opts.on(*token.arguments_for_option_parser) do |arg|
|
56
|
-
|
60
|
+
token.names_and_aliases.each do |name|
|
57
61
|
options[name] = arg
|
58
62
|
options[name.to_sym] = arg
|
59
63
|
end
|
data/lib/gli/version.rb
CHANGED
data/test/tc_gli.rb
CHANGED
@@ -419,11 +419,11 @@ class TC_testGLI < Clean::Test::TestCase
|
|
419
419
|
c.flag :i
|
420
420
|
c.flag :s
|
421
421
|
c.action do |g,o,a|
|
422
|
-
assert_equal "
|
423
|
-
assert_equal
|
422
|
+
assert_equal "1", o[:i]
|
423
|
+
assert_equal nil, o[:s]
|
424
424
|
end
|
425
425
|
end
|
426
|
-
@app.run(['foo',
|
426
|
+
@app.run(['foo','a'])
|
427
427
|
end
|
428
428
|
|
429
429
|
def test_switch_with_default_of_true
|
@@ -480,6 +480,39 @@ class TC_testGLI < Clean::Test::TestCase
|
|
480
480
|
@app.run(['foo', '-i5','-sa'])
|
481
481
|
end
|
482
482
|
|
483
|
+
def test_default_values_are_available_on_all_aliases
|
484
|
+
@app.reset
|
485
|
+
@app.on_error { |e| raise e }
|
486
|
+
|
487
|
+
@app.default_value "global_default"
|
488
|
+
@app.flag [ :f, :flag ]
|
489
|
+
|
490
|
+
@global_options = {}
|
491
|
+
@command_options = {}
|
492
|
+
|
493
|
+
@app.command [:foo] do |c|
|
494
|
+
c.default_value "command_default"
|
495
|
+
c.flag [ :c,:commandflag]
|
496
|
+
|
497
|
+
c.action do |g,o,a|
|
498
|
+
@global_options = g
|
499
|
+
@command_options = o
|
500
|
+
end
|
501
|
+
end
|
502
|
+
|
503
|
+
@app.run(["foo"])
|
504
|
+
|
505
|
+
assert_equal "global_default", @global_options[:f]
|
506
|
+
assert_equal "global_default", @global_options[:flag]
|
507
|
+
assert_equal "global_default", @global_options["f"]
|
508
|
+
assert_equal "global_default", @global_options["flag"]
|
509
|
+
|
510
|
+
assert_equal "command_default", @command_options[:c]
|
511
|
+
assert_equal "command_default", @command_options[:commandflag]
|
512
|
+
assert_equal "command_default", @command_options["c"]
|
513
|
+
assert_equal "command_default", @command_options["commandflag"]
|
514
|
+
end
|
515
|
+
|
483
516
|
def test_exits_zero_on_success
|
484
517
|
@app.reset
|
485
518
|
assert_equal 0,@app.run([]),@fake_stderr.to_s
|
data/test/tc_subcommands.rb
CHANGED
@@ -137,10 +137,12 @@ class TC_testSubCommand < Clean::Test::TestCase
|
|
137
137
|
|
138
138
|
def indifferent_hash(possibly_nil_hash)
|
139
139
|
return {} if possibly_nil_hash.nil?
|
140
|
-
keys
|
141
|
-
|
142
|
-
|
143
|
-
|
140
|
+
possibly_nil_hash.keys.each do |key|
|
141
|
+
if key.kind_of? Symbol
|
142
|
+
possibly_nil_hash[key.to_s] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_s)
|
143
|
+
elsif key.kind_of? String
|
144
|
+
possibly_nil_hash[key.to_sym] = possibly_nil_hash[key] unless possibly_nil_hash.has_key?(key.to_sym)
|
145
|
+
end
|
144
146
|
end
|
145
147
|
possibly_nil_hash
|
146
148
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|