gli 2.13.4 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72425f3996eedb08a03af7c55d8fa50dc358659d
4
- data.tar.gz: 41634461e71b54e34f156f59e85c02fab64e6410
3
+ metadata.gz: 71f12230a16a02ce456bc50cb4f3729797d3a21e
4
+ data.tar.gz: d24fb65d109f0454befb7a7d2f31c27cca91eb86
5
5
  SHA512:
6
- metadata.gz: b3c97518e3500e9853f2d5240c08db8655b0c771b1de9f1e453478ce3cefa16612a2aef458febde8246cdabcfda409db43f8a5770113e80841c22f82666ed24b
7
- data.tar.gz: 55df85338820f8b1ebb2d33e98009346641c382b34be7494de9688a90450702a910258fcbbd8a111bb444619db67e9754a62a001d50428113bc66e0ad21f9421
6
+ metadata.gz: 4abb85d5fc3cd970a6662f5c7f2da49c912e8874644537f9609b70f61969779f14f20525a1d4f12a7b071c90dc01ec489ead94378baefbbfc91d63044fd0bf9f
7
+ data.tar.gz: 8b5271a476e203d4e0fc06f8de8dd4b5228078a5a6b0f0702166982e10c5eb830999137f092ab4f460cc996b0d5744774e8330caaf210f096d36eb9b80d293a4
@@ -3,10 +3,9 @@ notifications:
3
3
  on_success: always
4
4
  script: 'bundle exec rake test features'
5
5
  rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1
9
- - 2.2
6
+ - 2.1.8
7
+ - 2.2.4
8
+ - 2.3.0
10
9
  branches:
11
10
  only:
12
11
  - 'gli-2'
@@ -73,18 +73,15 @@ Get a more detailed walkthrough on the {main site}[http://davetron5000.github.co
73
73
 
74
74
  == Supported Platforms
75
75
 
76
- Known to work on
76
+ Tests should be passing supported MRI Rubies (see +.travis.yml+ for specifics).
77
+
78
+ Due to the vagaries of Travis, I can't keep the test suite running on unsupported Rubies, however GLI has been used on older ones, like:
77
79
 
78
80
  * 1.8.7
79
81
  * 1.9.2
80
82
  * 1.9.3
81
- * 2.0.0
82
- * 2.1.0
83
83
  * Ruby Enterprise Edition 1.8.7
84
- * Rubinius 1.0.1
85
- * JRuby 1.6.4
86
-
87
- If you're interested in other versions of Ruby, let me know, and I'll add them to my test suite
84
+ * JRuby
88
85
 
89
86
  == Documentation
90
87
 
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
22
22
  s.bindir = 'bin'
23
23
  s.rubyforge_project = 'gli'
24
24
  s.add_development_dependency('rake', '~> 0.9.2.2')
25
- s.add_development_dependency('rdoc', '~> 3.11')
25
+ s.add_development_dependency('rdoc')
26
26
  s.add_development_dependency('rainbow', '~> 1.1.1')
27
27
  s.add_development_dependency('clean_test')
28
28
  s.add_development_dependency('cucumber')
@@ -24,12 +24,10 @@ module GLI
24
24
 
25
25
  def description_with_default(option)
26
26
  if option.kind_of? Flag
27
- required = if option.required?
28
- 'required, '
29
- else
30
- ''
31
- end
32
- String(option.description) + " (#{required}default: #{option.safe_default_value || 'none'})"
27
+ required = option.required? ? 'required, ' : ''
28
+ multiple = option.multiple? ? 'may be used more than once, ' : ''
29
+
30
+ String(option.description) + " (#{required}#{multiple}default: #{option.safe_default_value || 'none'})"
33
31
  else
34
32
  String(option.description) + (option.default_value ? " (default: enabled)" : "")
35
33
  end
@@ -75,6 +75,7 @@ module GLI
75
75
  # +:arg_name+:: the arg name, instead of using #arg_name
76
76
  # +:must_match+:: A regexp that the flag's value must match or an array of allowable values
77
77
  # +:type+:: A Class (or object you passed to GLI::App#accept) to trigger type coversion
78
+ # +:multiple+:: if true, flag may be used multiple times and values are stored in an array
78
79
  #
79
80
  # Example:
80
81
  #
@@ -24,17 +24,18 @@ module GLI
24
24
  # :must_match:: a regexp that the flag's value must match
25
25
  # :type:: a class to convert the value to
26
26
  # :required:: if true, this flag must be specified on the command line
27
+ # :multiple:: if true, flag may be used multiple times and values are stored in an array
27
28
  # :mask:: if true, the default value of this flag will not be output in the help.
28
29
  # This is useful for password flags where you might not want to show it
29
30
  # on the command-line.
30
31
  def initialize(names,options)
31
32
  super(names,options)
32
33
  @argument_name = options[:arg_name] || "arg"
33
- @default_value = options[:default_value]
34
34
  @must_match = options[:must_match]
35
35
  @type = options[:type]
36
36
  @mask = options[:mask]
37
37
  @required = options[:required]
38
+ @multiple = options[:multiple]
38
39
  end
39
40
 
40
41
  # True if this flag is required on the command line
@@ -42,12 +43,32 @@ module GLI
42
43
  @required
43
44
  end
44
45
 
46
+ # True if the flag may be used multiple times.
47
+ def multiple?
48
+ @multiple
49
+ end
45
50
 
46
51
  def safe_default_value
47
52
  if @mask
48
53
  "********"
49
54
  else
50
- default_value
55
+ # This uses @default_value instead of the `default_value` method because
56
+ # this method is only used for display, and for flags that may be passed
57
+ # multiple times, we want to display whatever is set in the code as the
58
+ # the default, or the string "none" rather than displaying an empty
59
+ # array.
60
+ @default_value
61
+ end
62
+ end
63
+
64
+ # The default value for this flag. Uses the value passed if one is set;
65
+ # otherwise uses `[]` if the flag support multiple arguments and `nil` if
66
+ # it does not.
67
+ def default_value
68
+ if @default_value
69
+ @default_value
70
+ elsif @multiple
71
+ []
51
72
  end
52
73
  end
53
74
 
@@ -58,8 +58,15 @@ module GLI
58
58
  tokens.each do |ignore,token|
59
59
  opts.on(*token.arguments_for_option_parser) do |arg|
60
60
  token.names_and_aliases.each do |name|
61
- options[name] = arg
62
- options[name.to_sym] = arg
61
+ if token.kind_of?(Flag) && token.multiple?
62
+ options[name] ||= []
63
+ options[name.to_sym] ||= []
64
+ options[name] << arg
65
+ options[name.to_sym] << arg
66
+ else
67
+ options[name] = arg
68
+ options[name.to_sym] = arg
69
+ end
63
70
  end
64
71
  end
65
72
  end
@@ -1,5 +1,5 @@
1
1
  module GLI
2
2
  unless const_defined? :VERSION
3
- VERSION = '2.13.4'
3
+ VERSION = '2.14.0'
4
4
  end
5
5
  end
@@ -717,6 +717,48 @@ class TC_testGLI < Clean::Test::TestCase
717
717
  assert_equal 'crud',@baz.value
718
718
  end
719
719
 
720
+ def test_that_flags_can_be_used_multiple_times
721
+ @app.reset
722
+ @app.flag :flag, :multiple => true
723
+ @app.command :foo do |c|
724
+ c.action do |options, _, _|
725
+ @flag = options[:flag]
726
+ end
727
+ end
728
+
729
+ assert_equal 0,@app.run(%w(--flag 1 --flag=2 --flag 3 foo)),@fake_stderr.to_s
730
+
731
+ assert_equal ['1','2','3'],@flag
732
+ end
733
+
734
+ def test_that_multiple_use_flags_are_empty_arrays_by_default
735
+ @app.reset
736
+ @app.flag :flag, :multiple => true
737
+ @app.command :foo do |c|
738
+ c.action do |options, _, _|
739
+ @flag = options[:flag]
740
+ end
741
+ end
742
+
743
+ assert_equal 0,@app.run(['foo']),@fake_stderr.to_s
744
+
745
+ assert_equal [],@flag
746
+ end
747
+
748
+ def test_that_multiple_use_flags_can_take_other_defaults
749
+ @app.reset
750
+ @app.flag :flag, :multiple => true, :default_value => ['1']
751
+ @app.command :foo do |c|
752
+ c.action do |options, _, _|
753
+ @flag = options[:flag]
754
+ end
755
+ end
756
+
757
+ assert_equal 0,@app.run(['foo']),@fake_stderr.to_s
758
+
759
+ assert_equal ['1'],@flag
760
+ end
761
+
720
762
  def test_that_we_mutate_ARGV_by_default
721
763
  @app.reset
722
764
  @app.flag :f
@@ -302,20 +302,20 @@ private
302
302
  unless omit_options
303
303
  flags.each do |(description,arg,flag_names)|
304
304
  desc description
305
- arg_name arg
306
- flag flag_names
305
+ arg_name arg
306
+ flag flag_names
307
307
  end
308
308
 
309
309
  switches.each do |(description,switch_names)|
310
310
  desc description
311
- switch switch_names
311
+ switch switch_names
312
312
  end
313
313
  end
314
314
 
315
315
  commands.each do |(description,command_names)|
316
316
  desc description
317
- command command_names do |c|
318
- c.action {}
317
+ command command_names do |c|
318
+ c.action {}
319
319
  end
320
320
  end
321
321
  end
@@ -363,7 +363,7 @@ private
363
363
  def any_option
364
364
  ('a'..'z').to_a[@option_index].tap { @option_index += 1 }
365
365
  end
366
-
366
+
367
367
  def any_long_option
368
368
  Faker::Lorem.words(10)[rand(10)]
369
369
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gli
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.13.4
4
+ version: 2.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Copeland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-25 00:00:00.000000000 Z
11
+ date: 2016-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rdoc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '3.11'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '3.11'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rainbow
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -277,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
277
  version: '0'
278
278
  requirements: []
279
279
  rubyforge_project: gli
280
- rubygems_version: 2.4.8
280
+ rubygems_version: 2.5.1
281
281
  signing_key:
282
282
  specification_version: 4
283
283
  summary: Build command-suite CLI apps that are awesome.