trollop 1.2 → 1.3

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 +6 -0
  2. data/lib/trollop.rb +10 -10
  3. data/test/test_trollop.rb +22 -0
  4. metadata +1 -1
@@ -1,3 +1,9 @@
1
+ == 1.3 / 2007-01-31
2
+ * Wrap at (screen width - 1) instead of screen width.
3
+ * User can override --help and --version.
4
+ * Bugfix in handling of -v and -h.
5
+ * More tests to confirm the above.
6
+
1
7
  == 1.2 / 2007-01-31
2
8
  * Minor documentation tweaks.
3
9
  * Removed hoe dependency.
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Trollop
7
7
 
8
- VERSION = "1.2"
8
+ VERSION = "1.3"
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.
@@ -78,7 +78,7 @@ class Parser
78
78
  ## * :required: if set to true, the argument must be provided on the
79
79
  ## commandline.
80
80
  def opt name, desc="", opts={}
81
- raise ArgumentError, "you already have an argument named #{name.inspect}" if @specs.member? name
81
+ raise ArgumentError, "you already have an argument named '#{name}'" if @specs.member? name
82
82
 
83
83
  ## fill in :type
84
84
  opts[:type] =
@@ -209,18 +209,15 @@ class Parser
209
209
  required = {}
210
210
  found = {}
211
211
 
212
- opt :version, "Print version and exit" if @version unless @specs[:version]
213
- opt :help, "Show this message" unless @specs[:help]
212
+ opt :version, "Print version and exit" if @version unless @specs[:version] || @long["version"]
213
+ opt :help, "Show this message" unless @specs[:help] || @long["help"]
214
214
 
215
215
  @specs.each do |name, opts|
216
216
  required[name] = true if opts[:required]
217
217
  vals[name] = opts[:default]
218
218
  end
219
219
 
220
- @leftovers = each_arg args do |arg, param|
221
- raise VersionNeeded if @version && %w(-v --version).include?(arg)
222
- raise HelpNeeded if %w(-h --help).include?(arg)
223
-
220
+ @leftovers = each_arg args do |arg, param|
224
221
  name =
225
222
  case arg
226
223
  when /^-([^-])$/
@@ -233,6 +230,9 @@ class Parser
233
230
  raise CommandlineError, "unknown argument '#{arg}'" unless name
234
231
  raise CommandlineError, "option '#{arg}' specified multiple times" if found[name]
235
232
 
233
+ raise VersionNeeded if name == :version
234
+ raise HelpNeeded if name == :help
235
+
236
236
  found[name] = true
237
237
  opts = @specs[name]
238
238
 
@@ -320,13 +320,13 @@ class Parser
320
320
  else
321
321
  ""
322
322
  end
323
- stream.puts wrap(desc, :width => width - rightcol_start, :prefix => rightcol_start)
323
+ stream.puts wrap(desc, :width => width - rightcol_start - 1, :prefix => rightcol_start)
324
324
  end
325
325
  end
326
326
 
327
327
  def wrap_line str, opts={} # :nodoc:
328
328
  prefix = opts[:prefix] || 0
329
- width = opts[:width] || self.width
329
+ width = opts[:width] || (self.width - 1)
330
330
  start = 0
331
331
  ret = []
332
332
  until start > str.length
@@ -341,6 +341,28 @@ EOM
341
341
  assert help[1] =~ /zzz/
342
342
  assert help[2] =~ /aaa/
343
343
  end
344
+
345
+ def test_version_and_help_short_args_can_be_overridden
346
+ @p.opt :verbose, "desc", :short => "-v"
347
+ @p.opt :hello, "desc", :short => "-h"
348
+ @p.version "version"
349
+
350
+ assert_nothing_raised { @p.parse(%w(-v)) }
351
+ assert_raises(VersionNeeded) { @p.parse(%w(--version)) }
352
+ assert_nothing_raised { @p.parse(%w(-h)) }
353
+ assert_raises(HelpNeeded) { @p.parse(%w(--help)) }
354
+ end
355
+
356
+ def test_version_and_help_long_args_cann_be_overridden
357
+ @p.opt :asdf, "desc", :long => "help"
358
+ @p.opt :asdf2, "desc2", :long => "version"
359
+ assert_nothing_raised { @p.parse %w() }
360
+ assert_nothing_raised { @p.parse %w(--help) }
361
+ assert_nothing_raised { @p.parse %w(--version) }
362
+ assert_nothing_raised { @p.parse %w(-h) }
363
+ assert_nothing_raised { @p.parse %w(-v) }
364
+ end
365
+
344
366
  end
345
367
 
346
368
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: trollop
5
5
  version: !ruby/object:Gem::Version
6
- version: "1.2"
6
+ version: "1.3"
7
7
  date: 2007-01-31 00:00:00 -08: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: