trollop 1.16.2 → 2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/FAQ.txt +57 -43
  2. data/History.txt +9 -0
  3. data/README.txt +14 -16
  4. data/lib/trollop.rb +42 -41
  5. data/test/test_trollop.rb +78 -35
  6. metadata +31 -37
data/FAQ.txt CHANGED
@@ -2,45 +2,37 @@ Trollop FAQ
2
2
  -----------
3
3
 
4
4
  Q: Why is it called "Trollop"?
5
- A: No reason.
5
+ A: No good reason. Something something option parsing.
6
6
 
7
7
  Q: Why should I use Trollop?
8
- A: Because it will take you FEWER LINES OF CODE to do reasonable option parsing
9
- than any other option parser out there.
10
-
11
- Look at this:
8
+ A: Because it will take you fewer lines of code to parse commandline arguments
9
+ than anything else out there.
12
10
 
11
+ Like this:
13
12
  opts = Trollop::options do
14
13
  opt :monkey, "Use monkey mode"
15
14
  opt :goat, "Use goat mode", :default => true
16
15
  opt :num_limbs, "Set number of limbs", :default => 4
17
16
  end
18
17
 
19
- That's it. And opts is a hash and you do whatever you want with it.
20
- Trivial. You don't have to mix option processing code blocks with the
21
- declarations. You don't have to make a class for every option (what is this,
22
- Java?). You don't have to write more than 1 line of code per option.
18
+ That's it. 'opts' will be a hash and you can do whatever you want with it.
19
+ You don't have to mix processing code with the declarations. You don't have
20
+ to make a class for every option (what is this, Java?). You don't have to
21
+ write more than 1 line of code per option.
23
22
 
24
23
  Plus, you get a beautiful help screen that detects your terminal width and
25
- wraps appropriately. C'mon, that's hot.
24
+ wraps appropriately.
26
25
 
27
26
  Q: What is the philosophy behind Trollop?
28
- A: Must a commandline option processor have a philosophy?
29
-
30
- Q: Seriously now. What is it?
31
- A: Ok, it's this: Trollop *just* does the parsing and gives you a hash table
32
- of the result. So whatever fancy logic or constraints you need, you can
33
- implement by operating on that hash table. Options that disable other
34
- options, fancy constraints involving multiple sets of values across multiple
35
- sets of options, etc. are all left for you to do manually.
27
+ A: Trollop does the parsing and gives you a hash table of options. You then
28
+ write whatever fancy constraint logic you need as regular Ruby code operating
29
+ on that hash table.
36
30
 
37
- (Trollop does support limited constraint setting (see #conflicts and
38
- #depends), but any non-trivial program will need to get fancier.)
31
+ (Trollop does support limited constraints (see #conflicts and #depends), but
32
+ any non-trivial program will probably need to get fancier.)
39
33
 
40
- The result is that using Trollop is pretty simple, and whatever bizarre
41
- logic you want, you can write yourself. And don't forget, you can call
42
- Trollop::die to abort the program and give a fancy options-related error
43
- message.
34
+ Then if you need to abort and tell the user to fix their command line at any
35
+ point, you can call #die and Trollop will do that for you in a pretty way.
44
36
 
45
37
  Q: What happens to the other stuff on the commandline?
46
38
  A: Anything Trollop doesn't recognize as an option or as an option parameter is
@@ -49,36 +41,58 @@ A: Anything Trollop doesn't recognize as an option or as an option parameter is
49
41
  Q: Does Trollop support multiple-value arguments?
50
42
  A: Yes. If you set the :type of an option to something plural, like ":ints",
51
43
  ":strings", ":doubles", ":floats", ":ios", it will accept multiple arguments
52
- on the commandline and the value will be an array of these.
44
+ on the commandline, and the value will be an array of the parameters.
53
45
 
54
46
  Q: Does Trollop support arguments that can be given multiple times?
55
47
  A: Yes. If you set :multi to true, then the argument can appear multiple times
56
48
  on the commandline, and the value will be an array of the parameters.
57
49
 
58
50
  Q: Does Trollop support subcommands?
59
- A: Yes. You get subcommand support by adding a call #stop_on within the options
60
- block, and passing the names of the subcommands to it. (See the third
61
- example on the webpage.) When Trollop encounters one of these subcommands on
62
- the commandline, it stops processing and returns.
51
+ A: Yes: you can direct Trollop to stop processing when it encounters certain
52
+ tokens. Then you can re-call Trollop with the subcommand-specific
53
+ configuration to process the rest of the commandline.
63
54
 
64
- ARGV at that point will contain the subcommand followed by any subcommand
65
- options, since Trollop has contained the rest. So you can consume the
66
- subcommand and call Trollop.options again with the particular options set
67
- for that subcommand.
55
+ See the third example on the webpage.
68
56
 
69
- If you don't know the subcommands ahead of time, you can call
57
+ (And if you don't know the subcommands ahead of time, you can call
70
58
  #stop_on_unknown, which will cause Trollop to stop when it encounters any
71
59
  unknown token. This might be more trouble than its worth if you're also
72
- passing filenames on the commandline.
73
-
74
- It's probably easier to see the example on the webpage than to read all
75
- that.
60
+ passing filenames on the commandline.)
76
61
 
77
62
  Q: Why does Trollop disallow numeric short argument names, like '-1' and '-9'?
78
63
  A: Because it's ambiguous whether these are arguments or negative integer or
79
- floating-point parameters to arguments. E.g., what about "-f -3". Is that a
80
- negative three parameter to -f, or two separate parameters?
64
+ floating-point parameters to arguments. E.g., is "-f -3" a negative floating
65
+ point parameter to -f, or two separate arguments?
66
+
67
+ Q: What was the big change in version 2.0?
68
+ A: The big change was boolean parameter (aka flag) handling. In pre-2.0,
69
+ not specifying a flag on the commandline would result in the option being set
70
+ to its default value; specifying it on the commandline would result in the
71
+ option being set to the opposite of its default value. This was weird for
72
+ options with a default of true:
73
+ opt :magic, "Use magic", default: true
74
+ Using --magic with the above configuration would result in a :magic => false
75
+ value in the options hash.
76
+
77
+ In 2.0, we introduce the GNU-style notion of a --no-x parameter. Now,
78
+ specifying --x will always set the option :x to true, regardless of its
79
+ default value, and specifying --no-x will always set the option :x to false,
80
+ regardless of its default value. The default value only comes into play when
81
+ neither form is given on the commandline.
82
+
83
+ E.g.:
84
+ opt :magic, "Use magic", :default => true
85
+
86
+ Using --magic will result in :magic => true, and --no-magic will result in
87
+ :magic => false, and neither will result in :magic => true.
88
+
89
+ There is one exception: if the option itself starts with a "no_", then you'll
90
+ get the opposite behavior:
91
+
92
+ opt :no_magic, "Don't use magic", :default => true
93
+
94
+ Using --magic will result in :no_magic => false, and --no-magic will result in
95
+ :no_magic => true, and neither will result in :no_magic => true.
96
+
97
+
81
98
 
82
- I could be very clever and detect when there are no arguments that require
83
- floating-point parameters, and allow such short option names in those cases,
84
- but opted for simplicity and consistency.
@@ -1,3 +1,12 @@
1
+ == 2.0 / 2012-08-11
2
+ * Change flag logic: --no-X will always be false, and --X will always be true,
3
+ regardless of default.
4
+ * For flags that default to true, display --no-X instead of --X in the help
5
+ menu. Accept both versions on the commandline.
6
+ * Fix a spurious warning
7
+ * Update Rakefile to 1.9
8
+ * Minor documentation fixes
9
+
1
10
  == 1.16.2 / 2010-04-06
2
11
  * Bugfix in Trollop::options. Thanks to Brian C. Thomas for pointing it out.
3
12
 
data/README.txt CHANGED
@@ -4,27 +4,26 @@ by William Morgan (http://masanjin.net/)
4
4
 
5
5
  Main page: http://trollop.rubyforge.org
6
6
 
7
- Release announcements and comments: http://all-thing.net/label/trollop
7
+ Release announcements and comments: http://masanjin.net/blog/label/trollop/.
8
8
 
9
9
  Documentation quickstart: See Trollop.options and then Trollop::Parser#opt.
10
10
  Also see the examples at http://trollop.rubyforge.org/.
11
11
 
12
12
  == DESCRIPTION
13
13
 
14
- Trollop is a commandline option parser for Ruby that just gets out of your
15
- way. One line of code per option is all you need to write. For that, you get a
16
- nice automatically-generated help page, robust option parsing, command
17
- subcompletion, and sensible defaults for everything you don't specify.
14
+ Trollop is a commandline option parser for Ruby that just gets out of your way.
15
+ One line of code per option is all you need to write. For that, you get a nice
16
+ automatically-generated help page, robust option parsing, and sensible defaults
17
+ for everything you don't specify.
18
18
 
19
- == FEATURES/PROBLEMS
19
+ == FEATURES
20
20
 
21
21
  - Dirt-simple usage.
22
+ - Single file. Throw it in lib/ if you don't want to make it a Rubygem dependency.
22
23
  - Sensible defaults. No tweaking necessary, much tweaking possible.
23
- - Support for long options, short options, short option bundling, and
24
- automatic type validation and conversion.
25
- - Support for subcommands.
24
+ - Support for long options, short options, subcommands, and automatic type validation and
25
+ conversion.
26
26
  - Automatic help message generation, wrapped to current screen width.
27
- - Lots of unit tests.
28
27
 
29
28
  == REQUIREMENTS
30
29
 
@@ -38,15 +37,14 @@ subcompletion, and sensible defaults for everything you don't specify.
38
37
 
39
38
  require 'trollop'
40
39
  opts = Trollop::options do
41
- opt :monkey, "Use monkey mode" # flag --monkey, default false
42
- opt :goat, "Use goat mode", :default => true # flag --goat, default true
43
- opt :num_limbs, "Number of limbs", :default => 4 # integer --num-limbs <i>, default to 4
44
- opt :num_thumbs, "Number of thumbs", :type => :int # integer --num-thumbs <i>, default nil
40
+ opt :monkey, "Use monkey mode" # flag --monkey, default false
41
+ opt :name, "Monkey name", :type => :string # string --name <s>, default nil
42
+ opt :num_limbs, "Number of limbs", :default => 4 # integer --num-limbs <i>, default to 4
45
43
  end
46
44
 
47
- p opts # a hash: { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
45
+ p opts # a hash: { :monkey=>false, :name=>nil, :num_limbs=>4, :help=>false }
48
46
 
49
47
  == LICENSE
50
48
 
51
- Copyright (c) 2008--2009 William Morgan. Trollop is distributed under the same
49
+ Copyright (c) 2008--2012 William Morgan. Trollop is distributed under the same
52
50
  terms as Ruby.
@@ -7,12 +7,12 @@ require 'date'
7
7
 
8
8
  module Trollop
9
9
 
10
- VERSION = "1.16.2"
10
+ VERSION = "2.0"
11
11
 
12
12
  ## Thrown by Parser in the event of a commandline error. Not needed if
13
13
  ## you're using the Trollop::options entry.
14
14
  class CommandlineError < StandardError; end
15
-
15
+
16
16
  ## Thrown by Parser if the user passes in '-h' or '--help'. Handled
17
17
  ## automatically by Trollop#options.
18
18
  class HelpNeeded < StandardError; end
@@ -154,12 +154,11 @@ class Parser
154
154
  ## a multi-valued argument. for that you have to specify a :type
155
155
  ## as well. (this is how we disambiguate an ambiguous situation;
156
156
  ## see the docs for Parser#opt for details.)
157
- disambiguated_default =
158
- if opts[:multi] && opts[:default].is_a?(Array) && !opts[:type]
159
- opts[:default].first
160
- else
161
- opts[:default]
162
- end
157
+ disambiguated_default = if opts[:multi] && opts[:default].is_a?(Array) && !opts[:type]
158
+ opts[:default].first
159
+ else
160
+ opts[:default]
161
+ end
163
162
 
164
163
  type_from_default =
165
164
  case disambiguated_default
@@ -193,15 +192,11 @@ class Parser
193
192
 
194
193
  ## fill in :long
195
194
  opts[:long] = opts[:long] ? opts[:long].to_s : name.to_s.gsub("_", "-")
196
- opts[:long] =
197
- case opts[:long]
198
- when /^--([^-].*)$/
199
- $1
200
- when /^[^-]/
201
- opts[:long]
202
- else
203
- raise ArgumentError, "invalid long option name #{opts[:long].inspect}"
204
- end
195
+ opts[:long] = case opts[:long]
196
+ when /^--([^-].*)$/; $1
197
+ when /^[^-]/; opts[:long]
198
+ else; raise ArgumentError, "invalid long option name #{opts[:long].inspect}"
199
+ end
205
200
  raise ArgumentError, "long option name #{opts[:long].inspect} is already taken; please specify a (different) :long" if @long[opts[:long]]
206
201
 
207
202
  ## fill in :short
@@ -295,19 +290,26 @@ class Parser
295
290
  vals[sym] = [] if opts[:multi] && !opts[:default] # multi arguments default to [], not nil
296
291
  end
297
292
 
298
- resolve_default_short_options
293
+ resolve_default_short_options!
299
294
 
300
295
  ## resolve symbols
301
296
  given_args = {}
302
297
  @leftovers = each_arg cmdline do |arg, params|
303
- sym = case arg
304
- when /^-([^-])$/
305
- @short[$1]
306
- when /^--([^-]\S*)$/
307
- @long[$1]
298
+ ## handle --no- forms
299
+ arg, negative_given = if arg =~ /^--no-([^-]\S*)$/
300
+ ["--#{$1}", true]
308
301
  else
309
- raise CommandlineError, "invalid argument syntax: '#{arg}'"
302
+ [arg, false]
310
303
  end
304
+
305
+ sym = case arg
306
+ when /^-([^-])$/; @short[$1]
307
+ when /^--([^-]\S*)$/; @long[$1] || @long["no-#{$1}"]
308
+ else; raise CommandlineError, "invalid argument syntax: '#{arg}'"
309
+ end
310
+
311
+ sym = nil if arg =~ /--no-/ # explicitly invalidate --no-no- arguments
312
+
311
313
  raise CommandlineError, "unknown argument '#{arg}'" unless sym
312
314
 
313
315
  if given_args.include?(sym) && !@specs[sym][:multi]
@@ -315,8 +317,8 @@ class Parser
315
317
  end
316
318
 
317
319
  given_args[sym] ||= {}
318
-
319
320
  given_args[sym][:arg] = arg
321
+ given_args[sym][:negative_given] = negative_given
320
322
  given_args[sym][:params] ||= []
321
323
 
322
324
  # The block returns the number of parameters taken.
@@ -358,8 +360,7 @@ class Parser
358
360
 
359
361
  ## parse parameters
360
362
  given_args.each do |sym, given_data|
361
- arg = given_data[:arg]
362
- params = given_data[:params]
363
+ arg, params, negative_given = given_data.values_at :arg, :params, :negative_given
363
364
 
364
365
  opts = @specs[sym]
365
366
  raise CommandlineError, "option '#{arg}' needs a parameter" if params.empty? && opts[:type] != :flag
@@ -368,7 +369,7 @@ class Parser
368
369
 
369
370
  case opts[:type]
370
371
  when :flag
371
- vals[sym] = !opts[:default]
372
+ vals[sym] = (sym.to_s =~ /^no_/ ? negative_given : !negative_given)
372
373
  when :int, :ints
373
374
  vals[sym] = params.map { |pg| pg.map { |p| parse_integer_parameter p, arg } }
374
375
  when :float, :floats
@@ -415,19 +416,19 @@ class Parser
415
416
  # chronic is not available
416
417
  end
417
418
  time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
418
- rescue ArgumentError => e
419
+ rescue ArgumentError
419
420
  raise CommandlineError, "option '#{arg}' needs a date"
420
421
  end
421
422
  end
422
423
 
423
424
  ## Print the help message to +stream+.
424
425
  def educate stream=$stdout
425
- width # just calculate it now; otherwise we have to be careful not to
426
+ width # hack: calculate it now; otherwise we have to be careful not to
426
427
  # call this unless the cursor's at the beginning of a line.
427
-
428
428
  left = {}
429
- @specs.each do |name, spec|
429
+ @specs.each do |name, spec|
430
430
  left[name] = "--#{spec[:long]}" +
431
+ (spec[:type] == :flag && spec[:default] ? ", --no-#{spec[:long]}" : "") +
431
432
  (spec[:short] && spec[:short] != :none ? ", -#{spec[:short]}" : "") +
432
433
  case spec[:type]
433
434
  when :flag; ""
@@ -627,7 +628,7 @@ private
627
628
  params
628
629
  end
629
630
 
630
- def resolve_default_short_options
631
+ def resolve_default_short_options!
631
632
  @order.each do |type, name|
632
633
  next unless type == :opt
633
634
  opts = @specs[name]
@@ -662,7 +663,7 @@ private
662
663
  end
663
664
 
664
665
  ## instance_eval but with ability to handle block arguments
665
- ## thanks to why: http://redhanded.hobix.com/inspect/aBlockCostume.html
666
+ ## thanks to _why: http://redhanded.hobix.com/inspect/aBlockCostume.html
666
667
  def cloaker &b
667
668
  (class << self; self; end).class_eval do
668
669
  define_method :cloaker_, &b
@@ -692,17 +693,16 @@ end
692
693
  ##
693
694
  ## require 'trollop'
694
695
  ## opts = Trollop::options do
695
- ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
696
- ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
697
- ## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
698
- ## opt :num_thumbs, "Number of thumbs", :type => :int # an integer --num-thumbs <i>, defaulting to nil
696
+ ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
697
+ ## opt :name, "Monkey name", :type => :string # a string --name <s>, defaulting to nil
698
+ ## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
699
699
  ## end
700
700
  ##
701
701
  ## ## if called with no arguments
702
- ## p opts # => { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
702
+ ## p opts # => {:monkey=>false, :name=>nil, :num_limbs=>4, :help=>false}
703
703
  ##
704
704
  ## ## if called with --monkey
705
- ## p opts # => {:monkey_given=>true, :monkey=>true, :goat=>true, :num_limbs=>4, :help=>false, :num_thumbs=>nil}
705
+ ## p opts # => {:monkey=>true, :name=>nil, :num_limbs=>4, :help=>false, :monkey_given=>true}
706
706
  ##
707
707
  ## See more examples at http://trollop.rubyforge.org.
708
708
  def options args=ARGV, *a, &b
@@ -728,8 +728,9 @@ end
728
728
  ## end
729
729
  ##
730
730
  ## opts = Trollop::with_standard_exception_handling p do
731
- ## p.parse ARGV
731
+ ## o = p.parse ARGV
732
732
  ## raise Trollop::HelpNeeded if ARGV.empty? # show help screen
733
+ ## o
733
734
  ## end
734
735
  ##
735
736
  ## Requires passing in the parser object.
@@ -3,6 +3,7 @@
3
3
  ## Copyright:: Copyright 2007 William Morgan
4
4
  ## License:: GNU GPL version 2
5
5
 
6
+ require 'rubygems'
6
7
  require 'test/unit'
7
8
  require 'stringio'
8
9
  require 'trollop'
@@ -41,7 +42,7 @@ class Trollop < ::Test::Unit::TestCase
41
42
  assert_raise(CommandlineError) { @p.parse(%w(--arg2)) }
42
43
  assert_raise(CommandlineError) { @p.parse(%w(--arg2 --arg3)) }
43
44
  end
44
-
45
+
45
46
  ## flags that take an argument error unless given one
46
47
  def test_argflags_demand_args
47
48
  @p.opt "goodarg", "desc", :type => String
@@ -247,24 +248,66 @@ class Trollop < ::Test::Unit::TestCase
247
248
  def test_conflicting_longs_detected
248
249
  assert_nothing_raised { @p.opt "goodarg", "desc", :long => "--goodarg" }
249
250
  assert_raise(ArgumentError) { @p.opt "badarg", "desc", :long => "--goodarg" }
250
- end
251
+ end
251
252
 
252
253
  ## two args can't have the same :short
253
254
  def test_conflicting_shorts_detected
254
255
  assert_nothing_raised { @p.opt "goodarg", "desc", :short => "-g" }
255
256
  assert_raise(ArgumentError) { @p.opt "badarg", "desc", :short => "-g" }
256
- end
257
+ end
257
258
 
258
- def test_flag_defaults
259
- @p.opt "defaultfalse", "desc"
260
- @p.opt "defaulttrue", "desc", :default => true
259
+ ## note: this behavior has changed in trollop 2.0!
260
+ def test_flag_parameters
261
+ @p.opt :defaultnone, "desc"
262
+ @p.opt :defaultfalse, "desc", :default => false
263
+ @p.opt :defaulttrue, "desc", :default => true
264
+
265
+ ## default state
266
+ opts = @p.parse []
267
+ assert_equal false, opts[:defaultnone]
268
+ assert_equal false, opts[:defaultfalse]
269
+ assert_equal true, opts[:defaulttrue]
270
+
271
+ ## specifying turns them on, regardless of default
272
+ opts = @p.parse %w(--defaultfalse --defaulttrue --defaultnone)
273
+ assert_equal true, opts[:defaultnone]
274
+ assert_equal true, opts[:defaultfalse]
275
+ assert_equal true, opts[:defaulttrue]
276
+
277
+ ## using --no- form turns them off, regardless of default
278
+ opts = @p.parse %w(--no-defaultfalse --no-defaulttrue --no-defaultnone)
279
+ assert_equal false, opts[:defaultnone]
280
+ assert_equal false, opts[:defaultfalse]
281
+ assert_equal false, opts[:defaulttrue]
282
+ end
283
+
284
+ ## note: this behavior has changed in trollop 2.0!
285
+ def test_flag_parameters_for_inverted_flags
286
+ @p.opt :no_default_none, "desc"
287
+ @p.opt :no_default_false, "desc", :default => false
288
+ @p.opt :no_default_true, "desc", :default => true
289
+
290
+ ## default state
261
291
  opts = @p.parse []
262
- assert_equal false, opts["defaultfalse"]
263
- assert_equal true, opts["defaulttrue"]
292
+ assert_equal false, opts[:no_default_none]
293
+ assert_equal false, opts[:no_default_false]
294
+ assert_equal true, opts[:no_default_true]
264
295
 
265
- opts = @p.parse %w(--defaultfalse --defaulttrue)
266
- assert_equal true, opts["defaultfalse"]
267
- assert_equal false, opts["defaulttrue"]
296
+ ## specifying turns them all on, regardless of default
297
+ opts = @p.parse %w(--no-default-false --no-default-true --no-default-none)
298
+ p opts
299
+ assert_equal true, opts[:no_default_none]
300
+ assert_equal true, opts[:no_default_false]
301
+ assert_equal true, opts[:no_default_true]
302
+
303
+ ## using dropped-no form turns them all off, regardless of default
304
+ opts = @p.parse %w(--default-false --default-true --default-none)
305
+ assert_equal false, opts[:no_default_none]
306
+ assert_equal false, opts[:no_default_false]
307
+ assert_equal false, opts[:no_default_true]
308
+
309
+ ## disallow double negatives for reasons of sanity preservation
310
+ assert_raise(CommandlineError) { @p.parse %w(--no-no-default-true) }
268
311
  end
269
312
 
270
313
  def test_special_flags_work
@@ -679,27 +722,27 @@ EOM
679
722
  assert_nothing_raised { @p.conflicts :one, :two }
680
723
  assert_nothing_raised { @p.parse %w(--one) }
681
724
  assert_nothing_raised { @p.parse %w(--two) }
682
- assert_raises(CommandlineError) { opts = @p.parse %w(--one --two) }
725
+ assert_raises(CommandlineError) { @p.parse %w(--one --two) }
683
726
 
684
727
  @p.opt :hello
685
728
  @p.opt :yellow
686
729
  @p.opt :mellow
687
730
  @p.opt :jello
688
731
  @p.conflicts :hello, :yellow, :mellow, :jello
689
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello --yellow --mellow --jello) }
690
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello --mellow --jello) }
691
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello --jello) }
732
+ assert_raises(CommandlineError) { @p.parse %w(--hello --yellow --mellow --jello) }
733
+ assert_raises(CommandlineError) { @p.parse %w(--hello --mellow --jello) }
734
+ assert_raises(CommandlineError) { @p.parse %w(--hello --jello) }
692
735
 
693
- assert_nothing_raised { opts = @p.parse %w(--hello) }
694
- assert_nothing_raised { opts = @p.parse %w(--jello) }
695
- assert_nothing_raised { opts = @p.parse %w(--yellow) }
696
- assert_nothing_raised { opts = @p.parse %w(--mellow) }
736
+ assert_nothing_raised { @p.parse %w(--hello) }
737
+ assert_nothing_raised { @p.parse %w(--jello) }
738
+ assert_nothing_raised { @p.parse %w(--yellow) }
739
+ assert_nothing_raised { @p.parse %w(--mellow) }
697
740
 
698
- assert_nothing_raised { opts = @p.parse %w(--mellow --one) }
699
- assert_nothing_raised { opts = @p.parse %w(--mellow --two) }
741
+ assert_nothing_raised { @p.parse %w(--mellow --one) }
742
+ assert_nothing_raised { @p.parse %w(--mellow --two) }
700
743
 
701
- assert_raises(CommandlineError) { opts = @p.parse %w(--mellow --two --jello) }
702
- assert_raises(CommandlineError) { opts = @p.parse %w(--one --mellow --two --jello) }
744
+ assert_raises(CommandlineError) { @p.parse %w(--mellow --two --jello) }
745
+ assert_raises(CommandlineError) { @p.parse %w(--one --mellow --two --jello) }
703
746
  end
704
747
 
705
748
  def test_conflict_error_messages
@@ -721,7 +764,7 @@ EOM
721
764
  assert_raises(ArgumentError) { @p.depends :one, :two }
722
765
  @p.opt :two
723
766
  assert_nothing_raised { @p.depends :one, :two }
724
- assert_nothing_raised { opts = @p.parse %w(--one --two) }
767
+ assert_nothing_raised { @p.parse %w(--one --two) }
725
768
  assert_raises(CommandlineError) { @p.parse %w(--one) }
726
769
  assert_raises(CommandlineError) { @p.parse %w(--two) }
727
770
 
@@ -730,17 +773,17 @@ EOM
730
773
  @p.opt :mellow
731
774
  @p.opt :jello
732
775
  @p.depends :hello, :yellow, :mellow, :jello
733
- assert_nothing_raised { opts = @p.parse %w(--hello --yellow --mellow --jello) }
734
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello --mellow --jello) }
735
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello --jello) }
776
+ assert_nothing_raised { @p.parse %w(--hello --yellow --mellow --jello) }
777
+ assert_raises(CommandlineError) { @p.parse %w(--hello --mellow --jello) }
778
+ assert_raises(CommandlineError) { @p.parse %w(--hello --jello) }
736
779
 
737
- assert_raises(CommandlineError) { opts = @p.parse %w(--hello) }
738
- assert_raises(CommandlineError) { opts = @p.parse %w(--mellow) }
780
+ assert_raises(CommandlineError) { @p.parse %w(--hello) }
781
+ assert_raises(CommandlineError) { @p.parse %w(--mellow) }
739
782
 
740
- assert_nothing_raised { opts = @p.parse %w(--hello --yellow --mellow --jello --one --two) }
741
- assert_nothing_raised { opts = @p.parse %w(--hello --yellow --mellow --jello --one --two a b c) }
783
+ assert_nothing_raised { @p.parse %w(--hello --yellow --mellow --jello --one --two) }
784
+ assert_nothing_raised { @p.parse %w(--hello --yellow --mellow --jello --one --two a b c) }
742
785
 
743
- assert_raises(CommandlineError) { opts = @p.parse %w(--mellow --two --jello --one) }
786
+ assert_raises(CommandlineError) { @p.parse %w(--mellow --two --jello --one) }
744
787
  end
745
788
 
746
789
  def test_depend_error_messages
@@ -1049,7 +1092,7 @@ EOM
1049
1092
  ARGV.clear
1050
1093
  ARGV.unshift "-h"
1051
1094
  assert_raises(SystemExit) do
1052
- opts = ::Trollop::options do
1095
+ ::Trollop::options do
1053
1096
  opt :potato
1054
1097
  end
1055
1098
  raise "broken"
@@ -1060,7 +1103,7 @@ EOM
1060
1103
  ARGV.clear
1061
1104
  ARGV.unshift "-v"
1062
1105
  assert_raises(SystemExit) do
1063
- opts = ::Trollop::options do
1106
+ ::Trollop::options do
1064
1107
  version "1.2"
1065
1108
  opt :potato
1066
1109
  end
@@ -1083,7 +1126,7 @@ EOM
1083
1126
  def test_simple_interface_handles_die
1084
1127
  ARGV.clear
1085
1128
  ARGV.unshift "--potato"
1086
- opts = ::Trollop::options do
1129
+ ::Trollop::options do
1087
1130
  opt :potato
1088
1131
  end
1089
1132
  assert_raises(SystemExit) { ::Trollop::die :potato, "is invalid" }
metadata CHANGED
@@ -1,65 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: trollop
3
- version: !ruby/object:Gem::Version
4
- version: 1.16.2
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.0'
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - William Morgan
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
-
12
- date: 2010-04-06 11:53:33 -04:00
13
- default_executable:
12
+ date: 2012-08-14 00:00:00.000000000 Z
14
13
  dependencies: []
14
+ description: ! 'Trollop is a commandline option parser for Ruby that just
15
15
 
16
- description: |-
17
- Trollop is a commandline option parser for Ruby that just
18
16
  gets out of your way. One line of code per option is all you need to write.
17
+
19
18
  For that, you get a nice automatically-generated help page, robust option
20
- parsing, command subcompletion, and sensible defaults for everything you don't
21
- specify.
19
+
20
+ parsing, command subcompletion, and sensible defaults for everything you don''t
21
+
22
+ specify.'
22
23
  email: wmorgan-trollop@masanjin.net
23
24
  executables: []
24
-
25
25
  extensions: []
26
-
27
26
  extra_rdoc_files: []
28
-
29
- files:
27
+ files:
30
28
  - lib/trollop.rb
31
29
  - test/test_trollop.rb
32
- - README.txt
33
- - release-script.txt
34
30
  - FAQ.txt
35
31
  - History.txt
36
- has_rdoc: true
32
+ - release-script.txt
33
+ - README.txt
37
34
  homepage: http://trollop.rubyforge.org
38
35
  licenses: []
39
-
40
36
  post_install_message:
41
37
  rdoc_options: []
42
-
43
- require_paths:
38
+ require_paths:
44
39
  - lib
45
- required_ruby_version: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - ">="
48
- - !ruby/object:Gem::Version
49
- version: "0"
50
- version:
51
- required_rubygems_version: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- version:
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
57
52
  requirements: []
58
-
59
53
  rubyforge_project: trollop
60
- rubygems_version: 1.3.5
54
+ rubygems_version: 1.8.23
61
55
  signing_key:
62
56
  specification_version: 3
63
- summary: Trollop is a commandline option parser for Ruby that just gets out of your way.
57
+ summary: Trollop is a commandline option parser for Ruby that just gets out of your
58
+ way.
64
59
  test_files: []
65
-