trollop 1.3 → 1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/History.txt +4 -0
  2. data/lib/trollop.rb +16 -9
  3. data/test/test_trollop.rb +13 -0
  4. metadata +2 -2
@@ -1,3 +1,7 @@
1
+ == 1.4 / 2007-03-26
2
+ * Disable short options with :short => :none.
3
+ * Minor bugfixes and error message improvements.
4
+
1
5
  == 1.3 / 2007-01-31
2
6
  * Wrap at (screen width - 1) instead of screen width.
3
7
  * User can override --help and --version.
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Trollop
7
7
 
8
- VERSION = "1.3"
8
+ VERSION = "1.4"
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.
@@ -130,27 +130,33 @@ class Parser
130
130
  raise ArgumentError, "long option name #{opts[:long].inspect} is already taken; please specify a (different) :long" if @long[opts[:long]]
131
131
 
132
132
  ## fill in :short
133
- opts[:short] = opts[:short].to_s if opts[:short]
133
+ opts[:short] = opts[:short].to_s if opts[:short] unless opts[:short] == :none
134
134
  opts[:short] =
135
135
  case opts[:short]
136
136
  when nil
137
- opts[:long].split(//).find { |c| c !~ /[\d]/ && !@short.member?(c) }
137
+ c = opts[:long].split(//).find { |c| c !~ /[\d]/ && !@short.member?(c) }
138
+ raise ArgumentError, "can't generate a short option name for #{opts[:long].inspect}: out of unique characters" unless c
139
+ c
138
140
  when /^-(.)$/
139
141
  $1
140
142
  when /^.$/
141
143
  opts[:short]
144
+ when :none
145
+ nil
142
146
  else
143
- raise ArgumentError, "invalid short option name #{opts[:long].inspect}"
147
+ raise ArgumentError, "invalid short option name '#{opts[:short].inspect}'"
144
148
  end
145
- raise ArgumentError, "can't generate a short option name (out of characters)" unless opts[:short]
146
- raise ArgumentError, "short option name #{opts[:short].inspect} is already taken; please specify a (different) :short" if @short[opts[:short]]
147
- raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ /[\d-]/
149
+ if opts[:short]
150
+ raise ArgumentError, "short option name #{opts[:short].inspect} is already taken; please specify a (different) :short" if @short[opts[:short]]
151
+ raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ /[\d-]/
152
+ end
148
153
 
149
154
  ## fill in :default for flags
150
155
  opts[:default] = false if opts[:type] == :flag && opts[:default].nil?
151
156
 
152
157
  opts[:desc] ||= desc
153
- @short[opts[:short]] = @long[opts[:long]] = name
158
+ @long[opts[:long]] = name
159
+ @short[opts[:short]] = name if opts[:short]
154
160
  @specs[name] = opts
155
161
  @order << [:opt, name]
156
162
  end
@@ -281,7 +287,8 @@ class Parser
281
287
 
282
288
  left = {}
283
289
  @specs.each do |name, spec|
284
- left[name] = "--#{spec[:long]}, -#{spec[:short]}" +
290
+ left[name] = "--#{spec[:long]}" +
291
+ (spec[:short] ? ", -#{spec[:short]}" : "") +
285
292
  case spec[:type]
286
293
  when :flag
287
294
  ""
@@ -120,6 +120,19 @@ class Trollop < ::Test::Unit::TestCase
120
120
  assert_equal true, opts["arg3"]
121
121
  end
122
122
 
123
+ def test_short_can_be_nothing
124
+ assert_nothing_raised do
125
+ @p.opt "arg", "desc", :short => :none
126
+ @p.parse []
127
+ end
128
+
129
+ sio = StringIO.new "w"
130
+ @p.educate sio
131
+ assert sio.string =~ /--arg:\s+desc/
132
+
133
+ assert_raise(CommandlineError) { @p.parse %w(-a) }
134
+ end
135
+
123
136
  ## two args can't have the same name
124
137
  def test_conflicting_names_are_detected
125
138
  assert_nothing_raised { @p.opt "goodarg", "desc" }
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: trollop
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.3"
7
- date: 2007-01-31 00:00:00 -08:00
6
+ version: "1.4"
7
+ date: 2007-03-26 00:00:00 -07:00
8
8
  summary: Trollop is YAFCLAP --- yet another fine commandline argument processing library for Ruby. Trollop is designed to provide the maximal amount of GNU-style argument processing in the minimum number of lines of code (for you, the programmer).
9
9
  require_paths:
10
10
  - lib