choice 0.1.7 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/CHANGELOG +2 -0
- data/Gemfile +3 -0
- data/README.rdoc +57 -55
- data/TODO +2 -6
- data/choice.gemspec +4 -0
- data/lib/choice.rb +18 -30
- data/lib/choice/version.rb +2 -2
- metadata +50 -7
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
M2I0MjZhZjM5MTY5YjFlZTJlNmY4NTQxN2U1MzQ1YmJiNmZjNDA2NA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 15f0c2eb270e5a078a4073be95b3bee511cddfbe
|
4
|
+
data.tar.gz: e31ced92d8f6b1cff0ae20b9edd151852d408412
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YjcwMDJkMjlhZDA5NzNiYjBkYTgwMGI5MWVmYWYyNTM4Nzg5OWNhNmQyNTlk
|
11
|
-
NzVhZDRiZGQ3NDQxY2U1YjNhYzllN2I0MWUxMzdkMjQ5YjM2YWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NWFlMzYyMGM0OWUzMWZjMTc1NTU1MjMyZGQ1ZDQxM2NlOGQ4OWE2MzViNzhh
|
14
|
-
ZWNjYjY1NWViZWY3MzVjNGE0NGUyZjljN2U5YjI2NmRkYjUzMTE1MjFhNjYy
|
15
|
-
MWUwMzhhNzI0YTgwNDM0ODYxODUzOGUyMjRlYzc1M2VmMTgwYzI=
|
6
|
+
metadata.gz: 16a9248efc0788034bda81cfccaee80b155b5cae18e31ace243e8f0488c7a8170c232c95f961c330aa9ee40215717e149bcfc5fbcf79e8520002d81e7328332d
|
7
|
+
data.tar.gz: 60f97f4404904fedd8b254cf9a148e7fe401b4d9729c6a40cd12748d3eef5b410443c696d509afe3e1929b3e968bbc475379c00872050ec7e84ae7ba7d918078
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Gemfile.lock
|
data/.travis.yml
CHANGED
data/CHANGELOG
CHANGED
data/Gemfile
ADDED
data/README.rdoc
CHANGED
@@ -1,12 +1,14 @@
|
|
1
|
+
{<img src="https://travis-ci.org/defunkt/choice.svg?branch=master" />}[https://travis-ci.org/defunkt/choice]
|
2
|
+
|
1
3
|
= Welcome to Choice
|
2
4
|
|
3
|
-
Choice is a small library for defining and parsing command line options. It
|
4
|
-
works awesomely with Highline[https://github.com/JEG2/highline] or other command
|
5
|
+
Choice is a small library for defining and parsing command line options. It
|
6
|
+
works awesomely with Highline[https://github.com/JEG2/highline] or other command
|
5
7
|
line interface libraries.
|
6
8
|
|
7
|
-
Choice was written by Chris Wanstrath as an exercise in test driving development
|
8
|
-
of a DSL. This project is still an infant: bugs are expected and tattling on them
|
9
|
-
is appreciated.
|
9
|
+
Choice was written by Chris Wanstrath as an exercise in test driving development
|
10
|
+
of a DSL. This project is still an infant: bugs are expected and tattling on them
|
11
|
+
is appreciated.
|
10
12
|
|
11
13
|
Installing is easy, with RubyGems. Give it a shot:
|
12
14
|
$ gem install choice
|
@@ -14,7 +16,7 @@ Installing is easy, with RubyGems. Give it a shot:
|
|
14
16
|
E-mail inquiries can be directed to mailto:chris[at]ozmm[dot]org.
|
15
17
|
|
16
18
|
Of course, Choice is licensed under the MIT License, which you can find included
|
17
|
-
in the LICENSE file or by surfing your World Wide Web browser of choice towards
|
19
|
+
in the LICENSE file or by surfing your World Wide Web browser of choice towards
|
18
20
|
http://www.opensource.org/licenses/mit-license.php.
|
19
21
|
|
20
22
|
== Using Choice
|
@@ -31,7 +33,7 @@ programs utilizing the library have been placed. Here's a snippet:
|
|
31
33
|
Choice.options do
|
32
34
|
header ''
|
33
35
|
header 'Specific options:'
|
34
|
-
|
36
|
+
|
35
37
|
option :host do
|
36
38
|
short '-h'
|
37
39
|
long '--host=HOST'
|
@@ -46,7 +48,7 @@ programs utilizing the library have been placed. Here's a snippet:
|
|
46
48
|
cast Integer
|
47
49
|
default 21
|
48
50
|
end
|
49
|
-
|
51
|
+
|
50
52
|
separator ''
|
51
53
|
separator 'Common options: '
|
52
54
|
|
@@ -61,42 +63,42 @@ programs utilizing the library have been placed. Here's a snippet:
|
|
61
63
|
desc 'Show version'
|
62
64
|
action do
|
63
65
|
puts "ftpd.rb FTP server v#{PROGRAM_VERSION}"
|
64
|
-
exit
|
66
|
+
exit
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
69
71
|
puts 'port: ' + Choice[:port]
|
70
72
|
|
71
|
-
Notice the last line. For free, you will be given a <tt>Choice.choices</tt>
|
72
|
-
hash which contain, at runtime, the options found and their values.
|
73
|
+
Notice the last line. For free, you will be given a <tt>Choice.choices</tt>
|
74
|
+
hash which contain, at runtime, the options found and their values.
|
73
75
|
|
74
76
|
<tt>Choice[:key]</tt> is a shortcut for <tt>Choice.choices[:key]</tt>.
|
75
77
|
|
76
|
-
Because we gave option <tt>:port</tt> a default of 21,
|
77
|
-
<tt>Choice[:port]</tt> should be 21 if we run ftpd.rb with no options.
|
78
|
+
Because we gave option <tt>:port</tt> a default of 21,
|
79
|
+
<tt>Choice[:port]</tt> should be 21 if we run ftpd.rb with no options.
|
78
80
|
Let's see.
|
79
81
|
|
80
82
|
$ ruby ftpd.rb
|
81
83
|
port: 21
|
82
|
-
|
84
|
+
|
83
85
|
Cool. On our system, port 21 is reserved. Let's use another port.
|
84
86
|
|
85
87
|
$ ruby ftpd.rb -p 2100
|
86
88
|
port: 2100
|
87
|
-
|
89
|
+
|
88
90
|
Alright. And, of course, there is the hard way of doing things.
|
89
91
|
|
90
92
|
$ ruby ftpd.rb --port=2100
|
91
93
|
port: 2100
|
92
94
|
|
93
|
-
That <tt>:version</tt> option looks pretty interesting, huh? I wonder what it
|
95
|
+
That <tt>:version</tt> option looks pretty interesting, huh? I wonder what it
|
94
96
|
does...
|
95
|
-
|
97
|
+
|
96
98
|
$ ruby ftpd.rb -v
|
97
99
|
ftpd.rb FTP server v4
|
98
100
|
|
99
|
-
That's not all, though. We also get a <tt>--help</tt> option for free.
|
101
|
+
That's not all, though. We also get a <tt>--help</tt> option for free.
|
100
102
|
|
101
103
|
$ ruby ftpd.rb --help
|
102
104
|
Usage: ftpd.rb [-hpv]
|
@@ -105,16 +107,16 @@ That's not all, though. We also get a <tt>--help</tt> option for free.
|
|
105
107
|
-h, --host=HOST The hostname or ip of the host to bind to (default 127.0.0.1)
|
106
108
|
-p, --port=PORT The port to listen on (default 21)
|
107
109
|
|
108
|
-
Common options:
|
110
|
+
Common options:
|
109
111
|
--help Show this message
|
110
112
|
-v, --version Show version
|
111
|
-
|
112
|
-
|
113
|
+
|
114
|
+
|
113
115
|
== The Choice.choices hash
|
114
116
|
|
115
|
-
For better or worse, the <tt>Choice.choices</tt> hash is a bit lazy. It does
|
116
|
-
not care how you access it. Using the above example, assume we have a
|
117
|
-
<tt>:port</tt> option and we replace the last line of our program with the
|
117
|
+
For better or worse, the <tt>Choice.choices</tt> hash is a bit lazy. It does
|
118
|
+
not care how you access it. Using the above example, assume we have a
|
119
|
+
<tt>:port</tt> option and we replace the last line of our program with the
|
118
120
|
following three lines:
|
119
121
|
|
120
122
|
puts 'port: ' + Choice.choices[:port]
|
@@ -130,8 +132,8 @@ Now, run it.
|
|
130
132
|
|
131
133
|
Lazy, huh?
|
132
134
|
|
133
|
-
Keep in mind that your option's key in the <tt>Choice.choices</tt> hash is
|
134
|
-
defined by the first parameter passed to option statement. This is perfectly
|
135
|
+
Keep in mind that your option's key in the <tt>Choice.choices</tt> hash is
|
136
|
+
defined by the first parameter passed to option statement. This is perfectly
|
135
137
|
legit, albeit somewhat confusing:
|
136
138
|
|
137
139
|
option :name do
|
@@ -140,16 +142,16 @@ legit, albeit somewhat confusing:
|
|
140
142
|
desc "Your handle."
|
141
143
|
end
|
142
144
|
|
143
|
-
You can access this option by using <tt>Choice.choices[:name]</tt>, not
|
145
|
+
You can access this option by using <tt>Choice.choices[:name]</tt>, not
|
144
146
|
<tt>:handle</tt>.
|
145
147
|
|
146
148
|
== Option options
|
147
149
|
|
148
150
|
Obviously, Choice revolves around the <tt>option</tt> statement, which receives
|
149
|
-
a block. Here are all the, er, options +option+ accepts. None of them are
|
151
|
+
a block. Here are all the, er, options +option+ accepts. None of them are
|
150
152
|
required but +short+ or +long+ must be present for Choice to know what to do.
|
151
153
|
|
152
|
-
Options must be defined in the context of a <tt>Choice.options</tt> block, as
|
154
|
+
Options must be defined in the context of a <tt>Choice.options</tt> block, as
|
153
155
|
seen above. This context is assumed for the following explanations.
|
154
156
|
|
155
157
|
For the quick learners, here's the list:
|
@@ -177,7 +179,7 @@ character.
|
|
177
179
|
Defines the long switch for an option. Expected to be a double dash followed by
|
178
180
|
a string, an equal sign (or a space), and another string.
|
179
181
|
|
180
|
-
There are two variants: longs where a parameter is required and longs where a
|
182
|
+
There are two variants: longs where a parameter is required and longs where a
|
181
183
|
parameter is optional, in which case the value will be +true+ if the option is
|
182
184
|
present.
|
183
185
|
|
@@ -191,7 +193,7 @@ we can do this:
|
|
191
193
|
|
192
194
|
$ ruby ftpd.rb --debug
|
193
195
|
debug: true
|
194
|
-
|
196
|
+
|
195
197
|
$ ruby ftpd.rb --debug=1
|
196
198
|
debug: 1
|
197
199
|
|
@@ -205,7 +207,7 @@ Assuming the same as above:
|
|
205
207
|
|
206
208
|
$ ruby ftpd.rb --debug 1
|
207
209
|
debug: 1
|
208
|
-
|
210
|
+
|
209
211
|
$ ruby ftpd.rb --debug
|
210
212
|
<help screen printed>
|
211
213
|
|
@@ -214,7 +216,7 @@ Assuming the same as above:
|
|
214
216
|
Often you may wish to allow users the ability to pass in multiple arguments and have
|
215
217
|
them all combined into an array. You can accomplish this by defining a +long+ and
|
216
218
|
setting the caps-argument to *ARG. Like this:
|
217
|
-
|
219
|
+
|
218
220
|
long '--suit *SUITS'
|
219
221
|
|
220
222
|
<tt>Choice.choices.suits</tt> will now return an array. Here's an example of usage:
|
@@ -234,7 +236,7 @@ As with the above, assume our program prints <tt>Choice.choices[:debug]</tt>:
|
|
234
236
|
|
235
237
|
default 'info'
|
236
238
|
|
237
|
-
If we don't pass in <tt>--debug</tt>, the <tt>:debug</tt> element of our hash
|
239
|
+
If we don't pass in <tt>--debug</tt>, the <tt>:debug</tt> element of our hash
|
238
240
|
will be 'info.'
|
239
241
|
|
240
242
|
$ ftpd.rb
|
@@ -246,7 +248,7 @@ will be 'info.'
|
|
246
248
|
=== desc
|
247
249
|
|
248
250
|
The description of this option. Fairly straightforward, with one little trick:
|
249
|
-
multiple +desc+ statements in a single option will be considered new desc lines.
|
251
|
+
multiple +desc+ statements in a single option will be considered new desc lines.
|
250
252
|
The desc lines will be printed in the order they are defined. Like this:
|
251
253
|
|
252
254
|
desc "Your hostname."
|
@@ -260,8 +262,8 @@ A snippet from your <tt>--help</tt> might then look like this:
|
|
260
262
|
|
261
263
|
=== cast
|
262
264
|
|
263
|
-
By default, all members of the <tt>Choice.choices</tt> hash are strings. If
|
264
|
-
you want something different, like an Integer for a port number, you can use
|
265
|
+
By default, all members of the <tt>Choice.choices</tt> hash are strings. If
|
266
|
+
you want something different, like an Integer for a port number, you can use
|
265
267
|
the +cast+ statement.
|
266
268
|
|
267
269
|
cast Integer
|
@@ -293,7 +295,7 @@ your option's "desc" value.
|
|
293
295
|
|
294
296
|
=== validate
|
295
297
|
|
296
|
-
The +validate+ statement accepts a regular expression which it will test
|
298
|
+
The +validate+ statement accepts a regular expression which it will test
|
297
299
|
against the value passed. If the test fails, the <tt>--help</tt> screen will
|
298
300
|
be printed. I love ports, so let's stick with that example:
|
299
301
|
|
@@ -315,8 +317,8 @@ I've told it so):
|
|
315
317
|
The +filter+ statement lets you play with a value before it goes into the
|
316
318
|
<tt>Choice.choices</tt> hash. If you use +cast+, this will occur post-casting.
|
317
319
|
|
318
|
-
In this program we're defining a :name option and saying we don't want any
|
319
|
-
crazy characters in it, then printing that element of the
|
320
|
+
In this program we're defining a :name option and saying we don't want any
|
321
|
+
crazy characters in it, then printing that element of the
|
320
322
|
<tt>Choice.choices</tt>+ hash:
|
321
323
|
|
322
324
|
filter do |value|
|
@@ -328,7 +330,7 @@ Now:
|
|
328
330
|
$ ruby ftpd.rb --name=c.hr.is
|
329
331
|
name: chris
|
330
332
|
|
331
|
-
You can probably think of better uses.
|
333
|
+
You can probably think of better uses.
|
332
334
|
|
333
335
|
=== action
|
334
336
|
|
@@ -337,7 +339,7 @@ is passed. See the <tt>--version</tt> example earlier.
|
|
337
339
|
|
338
340
|
=== required options
|
339
341
|
|
340
|
-
You can specify an option as being required by passing :required => true to the
|
342
|
+
You can specify an option as being required by passing :required => true to the
|
341
343
|
option definition. Choice will then print the help screen if this option is
|
342
344
|
not present. Please let your dear users know which options are required.
|
343
345
|
|
@@ -363,8 +365,8 @@ Passing an empty string to any of these options will print a newline.
|
|
363
365
|
|
364
366
|
=== banner
|
365
367
|
|
366
|
-
The banner is the first line printed when your program is called with
|
367
|
-
<tt>--help</tt>. By default, it will be something like this, based on the
|
368
|
+
The banner is the first line printed when your program is called with
|
369
|
+
<tt>--help</tt>. By default, it will be something like this, based on the
|
368
370
|
options defined:
|
369
371
|
|
370
372
|
Usage: ftpd.rb [-hpv]
|
@@ -384,7 +386,7 @@ are printed. Each header call is a newline. Check out the example above.
|
|
384
386
|
=== separator
|
385
387
|
|
386
388
|
As in the example above, you can put separators between options to help display
|
387
|
-
the logical groupings of your options. Or whatever.
|
389
|
+
the logical groupings of your options. Or whatever.
|
388
390
|
|
389
391
|
separator "----"
|
390
392
|
|
@@ -394,14 +396,14 @@ To get a blank line, rock an empty string:
|
|
394
396
|
|
395
397
|
=== footer
|
396
398
|
|
397
|
-
The footer is displayed after all your options are displayed. Nothing new
|
399
|
+
The footer is displayed after all your options are displayed. Nothing new
|
398
400
|
here, works like the other options above.
|
399
401
|
|
400
402
|
footer "That's all there is to it!"
|
401
403
|
|
402
404
|
== Shorthand
|
403
405
|
|
404
|
-
Now that you've gone through all the hard stuff, here's the easy stuff: Choice
|
406
|
+
Now that you've gone through all the hard stuff, here's the easy stuff: Choice
|
405
407
|
options can be defined with a simple hash if you'd like. Here's an example,
|
406
408
|
from the tests:
|
407
409
|
|
@@ -411,7 +413,7 @@ from the tests:
|
|
411
413
|
options :band => { :short => "-b", :long => "--band=BAND", :cast => String, :desc => "Your favorite band.",
|
412
414
|
:validate => /\w+/ },
|
413
415
|
:animal => { :short => "-a", :long => "--animal=ANIMAL", :cast => String, :desc => "Your favorite animal." }
|
414
|
-
|
416
|
+
|
415
417
|
footer ""
|
416
418
|
footer "--help This message"
|
417
419
|
end
|
@@ -420,17 +422,17 @@ How's that tickle you? Real nice.
|
|
420
422
|
|
421
423
|
== It looks like poetry
|
422
424
|
|
423
|
-
That's it. Not much, I know. Maybe this will make handling your command
|
424
|
-
line options a bit easier. You can always use the option parser in the standard
|
425
|
-
Ruby library, but DSLs are just so cool. As one of my non-programmer friends
|
425
|
+
That's it. Not much, I know. Maybe this will make handling your command
|
426
|
+
line options a bit easier. You can always use the option parser in the standard
|
427
|
+
Ruby library, but DSLs are just so cool. As one of my non-programmer friends
|
426
428
|
said of a Ruby DSL: "It looks like poetry."
|
427
429
|
|
428
430
|
== It's totally broken
|
429
431
|
|
430
|
-
Okay, I knew this would happen. Do me a favor, if you have time: run +rake+
|
431
|
-
from the Choice directory and send me the output (mailto:chris[at]ozmm[dot]org).
|
432
|
-
This'll run the unit tests. Also, if you would, send me a bit of information
|
433
|
-
on your platform. Choice was tested on OS X and RHEL with a 2.4 kernel but who
|
432
|
+
Okay, I knew this would happen. Do me a favor, if you have time: run +rake+
|
433
|
+
from the Choice directory and send me the output (mailto:chris[at]ozmm[dot]org).
|
434
|
+
This'll run the unit tests. Also, if you would, send me a bit of information
|
435
|
+
on your platform. Choice was tested on OS X and RHEL with a 2.4 kernel but who
|
434
436
|
knows. Thanks a lot.
|
435
437
|
|
436
438
|
== Thanks to
|
data/TODO
CHANGED
@@ -1,7 +1,3 @@
|
|
1
1
|
1. Add support for defining the number of arguments an option takes.
|
2
|
-
2.
|
3
|
-
3.
|
4
|
-
4. Simplify anything in the Rakefile that has a more common current practice.
|
5
|
-
5. Either make everything work on 1.8.6+ or start deprecating older interpreters.
|
6
|
-
6. Publish docs similar to how we used to pub to RubyForge
|
7
|
-
7. Convert these to Github Issues
|
2
|
+
2. Publish docs similar to how we used to pub to RubyForge
|
3
|
+
3. Convert these to Github Issues
|
data/choice.gemspec
CHANGED
@@ -17,4 +17,8 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "test-unit", "~> 3.0"
|
20
24
|
end
|
data/lib/choice.rb
CHANGED
@@ -4,16 +4,10 @@ require 'choice/parser'
|
|
4
4
|
require 'choice/writer'
|
5
5
|
require 'choice/lazyhash'
|
6
6
|
|
7
|
-
if RUBY_VERSION < "1.9"
|
8
|
-
class Hash
|
9
|
-
alias_method(:key, :index) unless method_defined?(:key)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
7
|
#
|
14
8
|
# Usage of this module is lovingly detailed in the README file.
|
15
9
|
#
|
16
|
-
module Choice
|
10
|
+
module Choice
|
17
11
|
extend self
|
18
12
|
|
19
13
|
# The main method, which defines the options
|
@@ -24,7 +18,7 @@ module Choice
|
|
24
18
|
# Setup all instance variables
|
25
19
|
reset! if hash.empty?
|
26
20
|
@@args ||= ARGV
|
27
|
-
|
21
|
+
|
28
22
|
# Eval the passed block to define the options.
|
29
23
|
instance_eval(&block) if block_given?
|
30
24
|
|
@@ -36,13 +30,13 @@ module Choice
|
|
36
30
|
def options_from_hash(options_hash)
|
37
31
|
options_hash.each do |name, definition|
|
38
32
|
option = Option.new
|
39
|
-
definition.each do |key, value|
|
33
|
+
definition.each do |key, value|
|
40
34
|
Array(value).each { |hit| option.send(key, hit) }
|
41
35
|
end
|
42
36
|
@@options << [name.to_s, option]
|
43
37
|
end
|
44
38
|
end
|
45
|
-
|
39
|
+
|
46
40
|
# Return an array representing the rest of the command line arguments
|
47
41
|
def rest
|
48
42
|
@@rest
|
@@ -75,20 +69,14 @@ module Choice
|
|
75
69
|
# Define the banner, header, footer methods. All are just getters/setters
|
76
70
|
# of class variables.
|
77
71
|
%w[banner header footer].each do |method|
|
78
|
-
define_method(method) do |string|
|
72
|
+
define_method(method) do |string=nil|
|
79
73
|
variable = "@@#{method}"
|
80
74
|
return class_variable_get(variable) if string.nil?
|
81
75
|
val = class_variable_get(variable) || ''
|
82
76
|
class_variable_set(variable, val << string)
|
83
77
|
end
|
84
|
-
|
85
|
-
if RUBY_VERSION > "1.9"
|
86
|
-
original_method = "original_#{method}"
|
87
|
-
alias_method original_method, method
|
88
|
-
eval "def #{method}(string=nil); #{original_method}(string); end"
|
89
|
-
end
|
90
78
|
end
|
91
|
-
|
79
|
+
|
92
80
|
# Parse the provided args against the defined options.
|
93
81
|
def parse #:nodoc:
|
94
82
|
# Do nothing if options are not defined.
|
@@ -99,7 +87,7 @@ module Choice
|
|
99
87
|
help
|
100
88
|
else
|
101
89
|
begin
|
102
|
-
# Delegate parsing to our parser class, passing it our defined
|
90
|
+
# Delegate parsing to our parser class, passing it our defined
|
103
91
|
# options and the passed arguments.
|
104
92
|
@@choices, @@rest = Parser.parse(@@options, @@args)
|
105
93
|
@@choices = LazyHash.new(@@choices)
|
@@ -109,19 +97,19 @@ module Choice
|
|
109
97
|
end
|
110
98
|
end
|
111
99
|
end
|
112
|
-
|
100
|
+
|
113
101
|
# Did we already parse the arguments?
|
114
102
|
def parsed? #:nodoc:
|
115
103
|
@@choices ||= false
|
116
104
|
end
|
117
|
-
|
105
|
+
|
118
106
|
# Print the help screen by calling our Writer object
|
119
107
|
def help #:nodoc:
|
120
|
-
Writer.help( { :banner => @@banner, :header => @@header,
|
121
|
-
:options => @@options, :footer => @@footer },
|
108
|
+
Writer.help( { :banner => @@banner, :header => @@header,
|
109
|
+
:options => @@options, :footer => @@footer },
|
122
110
|
output_to, exit_on_help? )
|
123
111
|
end
|
124
|
-
|
112
|
+
|
125
113
|
# Set the args, potentially to something other than ARGV.
|
126
114
|
def args=(args) #:nodoc:
|
127
115
|
@@args = args.dup.map { |a| a + '' }
|
@@ -132,11 +120,11 @@ module Choice
|
|
132
120
|
def args #:nodoc:
|
133
121
|
@@args
|
134
122
|
end
|
135
|
-
|
123
|
+
|
136
124
|
# Returns the arguments that follow an argument
|
137
125
|
def args_of(opt)
|
138
126
|
args_of_opt = []
|
139
|
-
|
127
|
+
|
140
128
|
# Return an array of the arguments between opt and the next option,
|
141
129
|
# which all start with "-"
|
142
130
|
@@args.slice(@@args.index(opt)+1, @@args.length).select do |arg|
|
@@ -148,24 +136,24 @@ module Choice
|
|
148
136
|
end
|
149
137
|
args_of_opt
|
150
138
|
end
|
151
|
-
|
139
|
+
|
152
140
|
# You can choose to not kill the script after the help screen is printed.
|
153
141
|
def dont_exit_on_help=(val) #:nodoc:
|
154
142
|
@@exit = true
|
155
143
|
end
|
156
|
-
|
144
|
+
|
157
145
|
# Do we want to exit on help?
|
158
146
|
def exit_on_help? #:nodoc:
|
159
147
|
@@exit rescue false
|
160
148
|
end
|
161
|
-
|
149
|
+
|
162
150
|
# If we want to write to somewhere other than STDOUT.
|
163
151
|
def output_to(target = nil) #:nodoc:
|
164
152
|
@@output_to ||= STDOUT
|
165
153
|
return @@output_to if target.nil?
|
166
154
|
@@output_to = target
|
167
155
|
end
|
168
|
-
|
156
|
+
|
169
157
|
# Reset all the class variables.
|
170
158
|
def reset! #:nodoc:
|
171
159
|
@@args = false
|
data/lib/choice/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: choice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Austin
|
@@ -9,8 +9,50 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-12-
|
13
|
-
dependencies:
|
12
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: test-unit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.0'
|
14
56
|
description: Choice is a simple little gem for easily defining and parsing command
|
15
57
|
line options with a friendly DSL.
|
16
58
|
email:
|
@@ -20,8 +62,10 @@ executables: []
|
|
20
62
|
extensions: []
|
21
63
|
extra_rdoc_files: []
|
22
64
|
files:
|
23
|
-
- .
|
65
|
+
- ".gitignore"
|
66
|
+
- ".travis.yml"
|
24
67
|
- CHANGELOG
|
68
|
+
- Gemfile
|
25
69
|
- LICENSE
|
26
70
|
- README.rdoc
|
27
71
|
- Rakefile
|
@@ -50,12 +94,12 @@ require_paths:
|
|
50
94
|
- lib
|
51
95
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
96
|
requirements:
|
53
|
-
- -
|
97
|
+
- - ">="
|
54
98
|
- !ruby/object:Gem::Version
|
55
99
|
version: '0'
|
56
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
101
|
requirements:
|
58
|
-
- -
|
102
|
+
- - ">="
|
59
103
|
- !ruby/object:Gem::Version
|
60
104
|
version: '0'
|
61
105
|
requirements: []
|
@@ -70,4 +114,3 @@ test_files:
|
|
70
114
|
- test/test_option.rb
|
71
115
|
- test/test_parser.rb
|
72
116
|
- test/test_writer.rb
|
73
|
-
has_rdoc:
|