trollop 1.12 → 1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 1.13 / 2009-03-16
2
+ * Fix parsing of "--longarg=<value with spaces>".
3
+
1
4
  == 1.12 / 2009-01-30
2
5
  * Fix some unit test failures in the last release. Should be more careful.
3
6
  * Make default short options only be assigned *after* all user-specified
data/README.txt CHANGED
@@ -6,7 +6,9 @@ Main page: http://trollop.rubyforge.org
6
6
 
7
7
  Release announcements and comments: http://all-thing.net/search/label/trollop
8
8
 
9
- Documentation quickstart: See Trollop::options and Trollop::Parser#opt.
9
+ Documentation quickstart: See Trollop::options (for some reason rdoc isn't
10
+ linking that; it's in the top right of the screen if you're browsing online)
11
+ and then Trollop::Parser#opt. Also see the examples at http://trollop.rubyforge.org/.
10
12
 
11
13
  == DESCRIPTION
12
14
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Trollop
7
7
 
8
- VERSION = "1.12"
8
+ VERSION = "1.13"
9
9
 
10
10
  ## Thrown by Parser in the event of a commandline error. Not needed if
11
11
  ## you're using the Trollop::options entry.
@@ -287,15 +287,14 @@ class Parser
287
287
  ## resolve symbols
288
288
  given_args = {}
289
289
  @leftovers = each_arg cmdline do |arg, params|
290
- sym =
291
- case arg
292
- when /^-([^-])$/
293
- @short[$1]
294
- when /^--([^-]\S*)$/
295
- @long[$1]
296
- else
297
- raise CommandlineError, "invalid argument syntax: '#{arg}'"
298
- end
290
+ sym = case arg
291
+ when /^-([^-])$/
292
+ @short[$1]
293
+ when /^--([^-]\S*)$/
294
+ @long[$1]
295
+ else
296
+ raise CommandlineError, "invalid argument syntax: '#{arg}'"
297
+ end
299
298
  raise CommandlineError, "unknown argument '#{arg}'" unless sym
300
299
 
301
300
  if given_args.include?(sym) && !@specs[sym][:multi]
@@ -491,7 +490,7 @@ private
491
490
  when /^--$/ # arg terminator
492
491
  remains += args[(i + 1) .. -1]
493
492
  return remains
494
- when /^--(\S+?)=(\S+)$/ # long argument with equals
493
+ when /^--(\S+?)=(.*)$/ # long argument with equals
495
494
  yield "--#{$1}", [$2]
496
495
  i += 1
497
496
  when /^--(\S+)$/ # long argument
@@ -548,7 +548,9 @@ EOM
548
548
  assert_equal "goat", opts[:arg]
549
549
  assert_nothing_raised { opts = @p.parse %w(--arg=goat) }
550
550
  assert_equal "goat", opts[:arg]
551
- assert_raises(CommandlineError) { opts = @p.parse %w(--arg= goat) }
551
+ ## actually, this next one is valid. empty string for --arg, and goat as a
552
+ ## leftover.
553
+ ## assert_raises(CommandlineError) { opts = @p.parse %w(--arg= goat) }
552
554
  end
553
555
 
554
556
  def test_auto_generated_long_names_convert_underscores_to_hyphens
@@ -990,6 +992,16 @@ EOM
990
992
  assert !opts[:aab]
991
993
  assert opts[:ccd]
992
994
  end
995
+
996
+ def test_accepts_arguments_with_spaces
997
+ @p.opt :arg1, "arg", :type => String
998
+ @p.opt :arg2, "arg2", :type => String
999
+
1000
+ opts = @p.parse ["--arg1", "hello there", "--arg2=hello there"]
1001
+ assert_equal "hello there", opts[:arg1]
1002
+ assert_equal "hello there", opts[:arg2]
1003
+ assert_equal 0, @p.leftovers.size
1004
+ end
993
1005
  end
994
1006
 
995
1007
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trollop
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.12"
4
+ version: "1.13"
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Morgan
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-30 00:00:00 -08:00
12
+ date: 2009-03-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: "Documentation quickstart: See Trollop::options and Trollop::Parser#opt. == DESCRIPTION == REQUIREMENTS * A burning desire to write less code. == INSTALL * gem install trollop == LICENSE Copyright (c) 2008 William Morgan. Trollop is distributed under the same terms as Ruby."
16
+ description: "Documentation quickstart: See Trollop::options (for some reason rdoc isn't linking that; it's in the top right of the screen if you're browsing online) and then Trollop::Parser#opt. Also see the examples at http://trollop.rubyforge.org/. == DESCRIPTION == REQUIREMENTS * A burning desire to write less code. == INSTALL * gem install trollop == LICENSE Copyright (c) 2008 William Morgan. Trollop is distributed under the same terms as Ruby."
17
17
  email: wmorgan-trollop@masanjin.net
18
18
  executables: []
19
19