trollop 1.8 → 1.8.1

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.
data/FAQ.txt CHANGED
@@ -1,15 +1,26 @@
1
1
  Trollop FAQ
2
2
  -----------
3
3
 
4
- Q: Whither Trollop?
5
- A: There are more than a few pre-existing commandline argument
6
- processing libraries for Ruby. I was never too happy with any of
7
- them. They all seemed to want me to type way too much for what I
8
- wanted to get done. I just wanted to parse some options and be
9
- done with it.
10
-
11
- Q: Whither "Trollop"?
12
- A: No reason. Just thought it sounded funny.
4
+ Q: Why should I use Trollop?
5
+ A: Because it will take you FEWER LINES OF CODE to do reasonable option
6
+ parsing than any other option parser in existence.
7
+
8
+ Look:
9
+
10
+ opts = Trollop::options do
11
+ opt :monkey, "Use monkey mode"
12
+ opt :goat, "Use goat mode", :default => true
13
+ opt :num_limbs, "Set number of limbs", :default => 4
14
+ end
15
+
16
+ That's it. And opts is a hash and you do whatever you want with it.
17
+ Trivial. You don't have to mix option processing code blocks with the
18
+ declarations. You don't have to make a class for every option (what is
19
+ this, Java?). You don't have to write more than 1 line of code per
20
+ option.
21
+
22
+ Q: Why is it called "Trollop"?
23
+ A: No reason.
13
24
 
14
25
  Q: Why does Trollop disallow numeric short argument names, like '-1'
15
26
  and '-9'?
@@ -1,3 +1,12 @@
1
+ == 1.8.1 / 2008-06-24
2
+
3
+ * Bugfix for short option autocreation
4
+ * More aggressive documentation
5
+
6
+ == 1.8 / 2008-06-16
7
+
8
+ * Sub-command support via Parser#stop_on
9
+
1
10
  == 1.7.2 / 2008-01-16
2
11
  * Ruby 1.9-ify. Apparently this means replacing :'s with ;'s.
3
12
 
data/README.txt CHANGED
@@ -8,19 +8,14 @@ Documentation quickstart: See Trollop::Parser.
8
8
 
9
9
  == DESCRIPTION
10
10
 
11
- Trollop is YAFCLAP --- yet another fine commandline argument processor
12
- for Ruby. Trollop is designed to provide the maximal amount of GNU-style
13
- argument processing in the minimum number of lines of code (for you, the
14
- programmer).
15
-
16
- Trollop provides a nice automatically-generated help page, robust option
17
- parsing, and sensible defaults for everything you don't specify.
18
-
19
- Trollop: getting you 90% of the way there with only 10% of the effort.
11
+ Trollop is a commandline option parser for Ruby that just gets out of your
12
+ way. One line of code per option is all you need to write. For that, you get
13
+ a nice automatically-generated help page, robust option parsing, command
14
+ subcompletion, and sensible defaults for everything you don't specify.
20
15
 
21
16
  == FEATURES/PROBLEMS
22
17
 
23
- - Simple usage.
18
+ - Dirt-simple usage.
24
19
  - Sensible defaults. No tweaking necessary, much tweaking possible.
25
20
  - Support for long options, short options, short option bundling,
26
21
  and automatic type validation and conversion.
@@ -30,7 +25,9 @@ Trollop: getting you 90% of the way there with only 10% of the effort.
30
25
 
31
26
  == SYNOPSIS
32
27
 
28
+ ####################
33
29
  ###### simple ######
30
+ ####################
34
31
 
35
32
  require 'trollop'
36
33
  opts = Trollop::options do
@@ -39,9 +36,11 @@ Trollop: getting you 90% of the way there with only 10% of the effort.
39
36
  opt :num_limbs, "Set number of limbs", :default => 4
40
37
  end
41
38
 
42
- p opts
39
+ p opts # { :monkey => false, :goat => true, :num_limbs => 4 }
43
40
 
41
+ ####################
44
42
  ###### medium ######
43
+ ####################
45
44
 
46
45
  require 'trollop'
47
46
  opts = Trollop::options do
@@ -61,8 +60,9 @@ Trollop: getting you 90% of the way there with only 10% of the effort.
61
60
  end
62
61
  Trollop::die :volume, "must be non-negative" if opts[:volume] < 0
63
62
  Trollop::die :file, "must exist" unless File.exist?(opts[:file]) if opts[:file]
64
-
63
+ ################################
65
64
  ##### sub-command support ######
65
+ ################################
66
66
 
67
67
  require 'trollop'
68
68
  global_opts = Trollop::options do
@@ -75,11 +75,13 @@ Trollop: getting you 90% of the way there with only 10% of the effort.
75
75
  opt :cmd_option, "This is an option only for the subcommand"
76
76
  end
77
77
 
78
- puts "global: #{global_opts.inspect}, cmd: #{cmd.inspect}, cmd options: #{cmd_opts.inspect}"
78
+ p global_opts
79
+ p cmd
80
+ p cmd_opts
79
81
 
80
82
  == REQUIREMENTS
81
83
 
82
- * none!
84
+ * A burning desire to write less code.
83
85
 
84
86
  == INSTALL
85
87
 
data/Rakefile CHANGED
@@ -27,7 +27,7 @@ task :upload_webpage => WWW_FILES do |t|
27
27
  end
28
28
 
29
29
  task :upload_docs => [:docs] do |t|
30
- sh "scp -Cr doc wmorgan@rubyforge.org:/var/www/gforge-projects/trollop/trollop"
30
+ sh "rsync -Paz -essh doc/* wmorgan@rubyforge.org:/var/www/gforge-projects/trollop/trollop/"
31
31
  end
32
32
 
33
33
  # vim: syntax=ruby
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Trollop
7
7
 
8
- VERSION = "1.8"
8
+ VERSION = "1.8.1"
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.
@@ -33,6 +33,9 @@ class Parser
33
33
  ## The set of values specifiable as the :type parameter to #opt.
34
34
  TYPES = [:flag, :boolean, :bool, :int, :integer, :string, :double, :float]
35
35
 
36
+ ## :nodoc:
37
+ INVALID_SHORT_ARG_REGEX = /[\d-]/
38
+
36
39
  ## The values from the commandline that were not interpreted by #parse.
37
40
  attr_reader :leftovers
38
41
 
@@ -137,7 +140,7 @@ class Parser
137
140
  opts[:short] =
138
141
  case opts[:short]
139
142
  when nil
140
- c = opts[:long].split(//).find { |c| c !~ /[\d]/ && !@short.member?(c) }
143
+ c = opts[:long].split(//).find { |c| c !~ INVALID_SHORT_ARG_REGEX && !@short.member?(c) }
141
144
  raise ArgumentError, "can't generate a short option name for #{opts[:long].inspect}: out of unique characters" unless c
142
145
  c
143
146
  when /^-(.)$/
@@ -151,7 +154,7 @@ class Parser
151
154
  end
152
155
  if opts[:short]
153
156
  raise ArgumentError, "short option name #{opts[:short].inspect} is already taken; please specify a (different) :short" if @short[opts[:short]]
154
- raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ /[\d-]/
157
+ raise ArgumentError, "a short option name can't be a number or a dash" if opts[:short] =~ INVALID_SHORT_ARG_REGEX
155
158
  end
156
159
 
157
160
  ## fill in :default for flags
@@ -109,7 +109,7 @@ class Trollop < ::Test::Unit::TestCase
109
109
  assert_raise(ArgumentError) { @p.opt "badarg3", "desc", :short => "--t" }
110
110
  end
111
111
 
112
- def test_short_names_determined_automatically
112
+ def test_short_names_created_automatically
113
113
  @p.opt "arg"
114
114
  @p.opt "arg2"
115
115
  @p.opt "arg3"
@@ -120,6 +120,29 @@ class Trollop < ::Test::Unit::TestCase
120
120
  assert_equal true, opts["arg3"]
121
121
  end
122
122
 
123
+ def test_short_autocreation_skips_dashes_and_numbers
124
+ @p.opt :arg # auto: a
125
+ @p.opt :arg_potato # auto: r
126
+ @p.opt :arg_muffin # auto: g
127
+ assert_nothing_raised { @p.opt :arg_daisy } # auto: d (not _)!
128
+ assert_nothing_raised { @p.opt :arg_r2d2f } # auto: f (not 2)!
129
+
130
+ opts = @p.parse %w(-f -d)
131
+ assert_equal true, opts[:arg_daisy]
132
+ assert_equal true, opts[:arg_r2d2f]
133
+ assert_equal false, opts[:arg]
134
+ assert_equal false, opts[:arg_potato]
135
+ assert_equal false, opts[:arg_muffin]
136
+ end
137
+
138
+ def test_short_autocreation_detects_running_out
139
+ @p.opt :arg1 # auto: a
140
+ @p.opt :arg2 # auto: r
141
+ @p.opt :arg3 # auto: g
142
+ assert_raises(ArgumentError) { @p.opt :arg4 }
143
+ assert_nothing_raised { @p.opt :argf }
144
+ end
145
+
123
146
  def test_short_can_be_nothing
124
147
  assert_nothing_raised do
125
148
  @p.opt "arg", "desc", :short => :none
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.8"
4
+ version: 1.8.1
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: 2008-06-16 00:00:00 -07:00
12
+ date: 2008-06-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: "== DESCRIPTION Trollop is YAFCLAP --- yet another fine commandline argument processor 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). - Simple usage. - Sensible defaults. No tweaking necessary, much tweaking possible. - Support for long options, short options, short option bundling, and automatic type validation and conversion. - Support for subcommands. - Automatic help message generation, wrapped to current screen width. - Lots of unit tests. Synopsis ###### simple ###### require 'trollop' opts = Trollop::options do opt :monkey, \"Use monkey mode\" opt :goat, \"Use goat mode\", :default => true opt :num_limbs, \"Set number of limbs\", :default => 4 end p opts ###### medium ###### require 'trollop' opts = Trollop::options do version \"test 1.2.3 (c) 2007 William Morgan\" banner <<-EOS Test is an awesome program that does something very, very important. Usage: test [options] <filenames>+ where [options] are: EOS opt :ignore, \"Ignore incorrect values\" opt :file, \"Extra data filename to read in, with a very long option description like this one\", :type => String opt :volume, \"Volume level\", :default => 3.0 opt :iters, \"Number of iterations\", :default => 5 end Trollop::die :volume, \"must be non-negative\" if opts[:volume] < 0 Trollop::die :file, \"must exist\" unless File.exist?(opts[:file]) if opts[:file] ##### sub-command support ######"
16
+ description: "== DESCRIPTION Trollop is a commandline option parser for Ruby that just gets out of your way. One line of code per option is all you need to write. For that, you get a nice automatically-generated help page, robust option parsing, command subcompletion, and sensible defaults for everything you don't specify. #################### ###### simple ###### #################### require 'trollop' opts = Trollop::options do opt :monkey, \"Use monkey mode\" opt :goat, \"Use goat mode\", :default => true opt :num_limbs, \"Set number of limbs\", :default => 4 end p opts # { :monkey => false, :goat => true, :num_limbs => 4 } #################### ###### medium ###### #################### require 'trollop' opts = Trollop::options do version \"test 1.2.3 (c) 2007 William Morgan\" banner <<-EOS Test is an awesome program that does something very, very important. Usage: test [options] <filenames>+ where [options] are: EOS opt :ignore, \"Ignore incorrect values\" opt :file, \"Extra data filename to read in, with a very long option description like this one\", :type => String opt :volume, \"Volume level\", :default => 3.0 opt :iters, \"Number of iterations\", :default => 5 end Trollop::die :volume, \"must be non-negative\" if opts[:volume] < 0 Trollop::die :file, \"must exist\" unless File.exist?(opts[:file]) if opts[:file] ################################ ##### sub-command support ###### ################################ require 'trollop' global_opts = Trollop::options do opt :global_option, \"This is a global option\" stop_on %w(sub-command-1 sub-command-2) end cmd = ARGV.shift cmd_opts = Trollop::options do opt :cmd_option, \"This is an option only for the subcommand\" end p global_opts p cmd p cmd_opts"
17
17
  email: wmorgan-trollop@masanjin.net
18
18
  executables: []
19
19
 
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  requirements: []
56
56
 
57
57
  rubyforge_project: trollop
58
- rubygems_version: 1.0.1
58
+ rubygems_version: 1.1.1
59
59
  signing_key:
60
60
  specification_version: 2
61
61
  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).