clip 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/History.txt +7 -0
  2. data/README.txt +1 -1
  3. data/Rakefile +2 -1
  4. data/lib/clip.rb +11 -6
  5. data/spec/clip_spec.rb +22 -3
  6. metadata +13 -6
@@ -1,3 +1,10 @@
1
+ === 1.0.2 / 2009-10-02
2
+
3
+ * Merged patches from Adam Salter:
4
+ * Added new "presence" method for options.
5
+ * Updated rspec usage to match the latest & greatest syntax
6
+ * Make descriptions optional for flags and options
7
+
1
8
  === 1.0.1 / 2009-01-06
2
9
 
3
10
  * Fixed a bug where generating help resulted in an infinite-loop
data/README.txt CHANGED
@@ -42,7 +42,7 @@ And it goes a little something like this...
42
42
 
43
43
  if options.valid?
44
44
  if options.verbose?
45
- puts options.host
45
+ puts options.server if options.server?
46
46
  puts options.port
47
47
  puts 'files:'
48
48
  options.files.each do |f|
data/Rakefile CHANGED
@@ -4,7 +4,8 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  require './lib/clip.rb'
6
6
 
7
- Hoe.new('clip', Clip::VERSION) do |p|
7
+ Hoe.spec('clip') do |p|
8
+ p.version = Clip::VERSION
8
9
  p.name = 'clip'
9
10
  p.developer('Alex Vollmer', 'alex.vollmer@gmail.com')
10
11
  p.description = p.paragraphs_of('README.txt', 5..5).join("\n\n")
@@ -15,7 +15,7 @@ def Clip(args=ARGV)
15
15
  end
16
16
 
17
17
  module Clip
18
- VERSION = "1.0.1"
18
+ VERSION = "1.0.2"
19
19
 
20
20
  ##
21
21
  # Indicates that the parser was incorrectly configured in the
@@ -47,11 +47,12 @@ module Clip
47
47
 
48
48
  ##
49
49
  # Declare an optional parameter for your parser. This creates an accessor
50
- # method matching the <tt>long</tt> parameter. The <tt>short</tt> parameter
51
- # indicates the single-letter equivalent. Options that use the '-'
50
+ # method matching the <tt>long</tt> parameter and a present method
51
+ # <tt>long?</tt>. The <tt>short</tt> parameter indicates
52
+ # the single-letter equivalent. Options that use the '-'
52
53
  # character as a word separator are converted to method names using
53
- # '_'. For example the name 'exclude-files' would create a method named
54
- # <tt>exclude_files</tt>.
54
+ # '_'. For example the name 'exclude-files' would create two methods named
55
+ # <tt>exclude_files</tt> and <tt>exclude_files?</tt>.
55
56
  #
56
57
  # When the <tt>:multi</tt> option is enabled, the associated accessor
57
58
  # method will return an <tt>Array</tt> instead of a single scalar value.
@@ -87,6 +88,10 @@ module Clip
87
88
  define_method(long.to_sym) do
88
89
  instance_variable_get(var_name)
89
90
  end
91
+
92
+ define_method("#{long}?") do
93
+ !instance_variable_get(var_name).nil?
94
+ end
90
95
  end
91
96
 
92
97
  self.options[short] = self.options[long] =
@@ -339,7 +344,7 @@ module Clip
339
344
  def initialize(short, long, options)
340
345
  @short = short
341
346
  @long = long
342
- @description = options[:desc]
347
+ @description = options[:desc] || ""
343
348
  @default = options[:default]
344
349
  @required = options[:required]
345
350
  @multi = options[:multi]
@@ -67,10 +67,13 @@ describe Clip do
67
67
  parser = parse('')
68
68
  parser.should respond_to(:server)
69
69
  parser.should respond_to(:server=)
70
+ parser.should respond_to(:server?)
70
71
  parser.should respond_to(:port)
71
- parser.should respond_to(:port)
72
+ parser.should respond_to(:port=)
73
+ parser.should respond_to(:port?)
72
74
  parser.should respond_to(:files)
73
75
  parser.should respond_to(:files=)
76
+ parser.should respond_to(:files?)
74
77
  parser.should respond_to(:verbose?)
75
78
  parser.should respond_to(:flag_verbose)
76
79
  parser.should respond_to(:allow_dashes?)
@@ -87,7 +90,9 @@ describe Clip do
87
90
  it "should set fields for flags with the given values" do
88
91
  parser = parse('--server localhost --port 8080 --files foo')
89
92
  parser.server.should eql("localhost")
93
+ parser.server?.should eql(true)
90
94
  parser.port.should eql("8080")
95
+ parser.port?.should eql(true)
91
96
  parser.should be_valid
92
97
  parser.should_not have_errors
93
98
  end
@@ -95,6 +100,7 @@ describe Clip do
95
100
  it "should map options with '-' to methods with '_'" do
96
101
  parser = parse('--exclude-from /Users --files foo')
97
102
  parser.exclude_from.should eql("/Users")
103
+ parser.exclude_from?.should eql(true)
98
104
  parser.should be_valid
99
105
  parser.should_not have_errors
100
106
  end
@@ -108,12 +114,15 @@ describe Clip do
108
114
  it "should map options with multiple '-' to methods with '_'" do
109
115
  parser = parse('--exclude-from-all /Users --files foo')
110
116
  parser.exclude_from_all.should eql("/Users")
117
+ parser.exclude_from_all?.should eql(true)
111
118
  parser.should be_valid
112
119
  parser.should_not have_errors
113
120
  end
114
121
 
115
122
  it "should be invalid for unknown options" do
116
123
  parser = parse('--non-existent')
124
+ parser.exclude_from_all?.should eql(false)
125
+ parser.exclude_from?.should eql(false)
117
126
  parser.should_not be_valid
118
127
  parser.should have_errors_on(:non_existent)
119
128
  end
@@ -133,7 +142,9 @@ describe Clip do
133
142
  parser.should_not have_errors
134
143
  parser.should be_valid
135
144
  parser.server.should eql("localhost")
145
+ parser.server?.should eql(true)
136
146
  parser.port.should eql("8080")
147
+ parser.port?.should eql(true)
137
148
  parser.should_not be_verbose
138
149
  end
139
150
  end
@@ -186,6 +197,14 @@ describe Clip do
186
197
  end
187
198
  end
188
199
 
200
+ it "should work if no description given" do
201
+ opts = Clip do |o|
202
+ o.opt 'X', 'no-description'
203
+ end
204
+ help = opts.to_s.split("\n")
205
+ help[1].should == "-X --no-description "
206
+ end
207
+
189
208
  it "should print out some sensible usage info for to_s" do
190
209
  help = opts("-s localhost").to_s.split("\n")
191
210
  help[0].should match(/Usage/)
@@ -301,7 +320,7 @@ describe Clip do
301
320
  end
302
321
  end
303
322
  describe "Remaining arguments for Clip.hash" do
304
- setup { Clip.reset_hash! }
323
+ before(:each) { Clip.reset_hash! }
305
324
 
306
325
  it "should be populated" do
307
326
  Clip.hash(['captain', 'lieutenant', '-c', 'jorge']).remainder.
@@ -448,7 +467,7 @@ describe Clip do
448
467
  end
449
468
 
450
469
  describe "when parsing ARGV as a hash" do
451
- setup { Clip.reset_hash! }
470
+ before(:each) { Clip.reset_hash! }
452
471
 
453
472
  it "should make sense of '-c my_config.yml'" do
454
473
  Clip.hash(['-c', 'config.yml']).should == { 'c' => 'config.yml' }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clip
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vollmer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-06 00:00:00 -08:00
12
+ date: 2009-10-03 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,9 +20,14 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.8.0
23
+ version: 2.3.3
24
24
  version:
25
- description: You like command-line parsing, but you hate all of the bloat. Why should you have to create a Hash, then create a parser, fill the Hash out then throw the parser away (unless you want to print out a usage message) and deal with a Hash? Why, for Pete's sake, should the parser and the parsed values be handled by two different objects?
25
+ description: |-
26
+ You like command-line parsing, but you hate all of the bloat. Why
27
+ should you have to create a Hash, then create a parser, fill the Hash
28
+ out then throw the parser away (unless you want to print out a usage
29
+ message) and deal with a Hash? Why, for Pete's sake, should the parser
30
+ and the parsed values be handled by two different objects?
26
31
  email:
27
32
  - alex.vollmer@gmail.com
28
33
  executables: []
@@ -43,6 +48,8 @@ files:
43
48
  - spec/clip_spec.rb
44
49
  has_rdoc: true
45
50
  homepage: http://clip.rubyforge.org
51
+ licenses: []
52
+
46
53
  post_install_message:
47
54
  rdoc_options:
48
55
  - --main
@@ -64,9 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
71
  requirements: []
65
72
 
66
73
  rubyforge_project: clip
67
- rubygems_version: 1.3.0
74
+ rubygems_version: 1.3.5
68
75
  signing_key:
69
- specification_version: 2
76
+ specification_version: 3
70
77
  summary: Command-line parsing made short and sweet
71
78
  test_files: []
72
79