trollop 1.16 → 1.16.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/History.txt +3 -0
  2. data/README.txt +14 -4
  3. data/lib/trollop.rb +17 -8
  4. metadata +5 -11
@@ -1,3 +1,6 @@
1
+ == 1.16.1 / 2010-04-05
2
+ * Bugfix in Trollop::die method introduced in last release.
3
+
1
4
  == 1.16 / 2010-04-01
2
5
  * Add Trollop::with_standard_exception_handling method for easing the use of Parser directly.
3
6
  * Handle scientific notation in float arguments, thanks to Will Fitzgerald.
data/README.txt CHANGED
@@ -6,10 +6,8 @@ Main page: http://trollop.rubyforge.org
6
6
 
7
7
  Release announcements and comments: http://all-thing.net/label/trollop
8
8
 
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
12
- http://trollop.rubyforge.org/.
9
+ Documentation quickstart: See Trollop.options and then Trollop::Parser#opt.
10
+ Also see the examples at http://trollop.rubyforge.org/.
13
11
 
14
12
  == DESCRIPTION
15
13
 
@@ -36,6 +34,18 @@ subcompletion, and sensible defaults for everything you don't specify.
36
34
 
37
35
  * gem install trollop
38
36
 
37
+ == SYNOPSIS
38
+
39
+ require 'trollop'
40
+ 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
45
+ end
46
+
47
+ p opts # a hash: { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
48
+
39
49
  == LICENSE
40
50
 
41
51
  Copyright (c) 2008--2009 William Morgan. Trollop is distributed under the same
@@ -7,7 +7,7 @@ require 'date'
7
7
 
8
8
  module Trollop
9
9
 
10
- VERSION = "1.16"
10
+ VERSION = "1.16.1"
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.
@@ -509,6 +509,17 @@ class Parser
509
509
  end
510
510
  end
511
511
 
512
+ ## The per-parser version of Trollop::die (see that for documentation).
513
+ def die arg, msg
514
+ if msg
515
+ $stderr.puts "Error: argument --#{@specs[arg][:long]} #{msg}."
516
+ else
517
+ $stderr.puts "Error: #{arg}."
518
+ end
519
+ $stderr.puts "Try --help for help."
520
+ exit(-1)
521
+ end
522
+
512
523
  private
513
524
 
514
525
  ## yield successive arg, parameter pairs
@@ -695,8 +706,8 @@ end
695
706
  ##
696
707
  ## See more examples at http://trollop.rubyforge.org.
697
708
  def options args=ARGV, *a, &b
698
- p = Parser.new(*a, &b)
699
- with_standard_exception_handling(p) { p.parse args }
709
+ @last_parser = Parser.new(*a, &b)
710
+ with_standard_exception_handling(p) { @last_parser.parse args }
700
711
  end
701
712
 
702
713
  ## If Trollop::options doesn't do quite what you want, you can create a Parser
@@ -758,13 +769,11 @@ end
758
769
  ##
759
770
  ## Trollop::die "need at least one filename" if ARGV.empty?
760
771
  def die arg, msg=nil
761
- if msg
762
- $stderr.puts "Error: argument --#{@p.specs[arg][:long]} #{msg}."
772
+ if @last_parser
773
+ @last_parser.die arg, msg
763
774
  else
764
- $stderr.puts "Error: #{arg}."
775
+ raise ArgumentError, "Trollop::die can only be called after Trollop::options"
765
776
  end
766
- $stderr.puts "Try --help for help."
767
- exit(-1)
768
777
  end
769
778
 
770
779
  module_function :options, :die, :with_standard_exception_handling
metadata CHANGED
@@ -1,11 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trollop
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 16
8
- version: "1.16"
4
+ version: 1.16.1
9
5
  platform: ruby
10
6
  authors:
11
7
  - William Morgan
@@ -13,7 +9,7 @@ autorequire:
13
9
  bindir: bin
14
10
  cert_chain: []
15
11
 
16
- date: 2010-04-01 16:46:01 -04:00
12
+ date: 2010-04-05 20:23:56 -04:00
17
13
  default_executable:
18
14
  dependencies: []
19
15
 
@@ -50,20 +46,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
50
46
  requirements:
51
47
  - - ">="
52
48
  - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
49
  version: "0"
50
+ version:
56
51
  required_rubygems_version: !ruby/object:Gem::Requirement
57
52
  requirements:
58
53
  - - ">="
59
54
  - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
55
  version: "0"
56
+ version:
63
57
  requirements: []
64
58
 
65
59
  rubyforge_project: trollop
66
- rubygems_version: 1.3.6
60
+ rubygems_version: 1.3.5
67
61
  signing_key:
68
62
  specification_version: 3
69
63
  summary: Trollop is a commandline option parser for Ruby that just gets out of your way.