clip 0.0.5 → 0.0.6

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/clip.rb +15 -20
  3. data/spec/clip_spec.rb +21 -1
  4. metadata +5 -4
@@ -1,3 +1,7 @@
1
+ === 0.0.6 / 2008-07-10
2
+
3
+ * Fixed a bug with getting the 'remainder' when only flags are declared.
4
+
1
5
  === 0.0.5 / 2008-06-12
2
6
 
3
7
  * Removed sample_parser from bin (technomancy)
@@ -13,7 +13,7 @@ def Clip(args=ARGV)
13
13
  end
14
14
 
15
15
  module Clip
16
- VERSION = "0.0.5"
16
+ VERSION = "0.0.6"
17
17
 
18
18
  ##
19
19
  # Indicates that the parser was incorrectly configured in the
@@ -139,35 +139,30 @@ module Clip
139
139
  puts help
140
140
  exit 0
141
141
  end
142
- param, value = nil, nil
142
+ option = nil
143
143
 
144
144
  args.each do |token|
145
145
  case token
146
146
  when /^-(-)?\w/
147
147
  consumed << token
148
148
  param = token.sub(/^-(-)?/, '').sub('-', '_').to_sym
149
- value = nil
150
- else
151
- if param
152
- consumed << token
153
- value = token
149
+ option = options[param]
150
+ unless option
151
+ @errors[param] = "Unrecognized parameter"
152
+ @valid = false
153
+ next
154
154
  end
155
- end
156
155
 
157
- option = options[param]
158
- if option
159
- if (value.nil? && option.kind_of?(Flag)) || value
160
- option.process(self, value)
156
+ if option.kind_of?(Flag)
157
+ option.process(self, nil)
158
+ option = nil
161
159
  end
162
160
  else
163
- @errors[param] = "Unrecognized parameter"
164
- @valid = false
165
- next
166
- end
167
-
168
- unless value.nil?
169
- param = nil
170
- value = nil
161
+ if option
162
+ consumed << token
163
+ option.process(self, token)
164
+ option = nil
165
+ end
171
166
  end
172
167
  end
173
168
 
@@ -186,12 +186,32 @@ describe Clip do
186
186
  end
187
187
  end
188
188
 
189
- describe "Additional arguments" do
189
+ describe "Remaining arguments" do
190
190
  it "should be made available" do
191
191
  parser = parse('--files foo alpha bravo')
192
192
  parser.files.should == %w[foo]
193
193
  parser.remainder.should == %w[alpha bravo]
194
194
  end
195
+
196
+ it "should be available when only flags are declared" do
197
+ opts = Clip('foobar') do |p|
198
+ p.flag 'v', 'verbose'
199
+ p.flag 'd', 'debug'
200
+ end
201
+ opts.remainder.should == ['foobar']
202
+ opts.should_not be_verbose
203
+ opts.should_not be_debug
204
+ end
205
+
206
+ it "should be available when flags are declared and parsed" do
207
+ opts = Clip('-v foobar') do |p|
208
+ p.flag 'v', 'verbose'
209
+ p.flag 'd', 'debug'
210
+ end
211
+ opts.remainder.should == ['foobar']
212
+ opts.should be_verbose
213
+ opts.should_not be_debug
214
+ end
195
215
  end
196
216
 
197
217
  describe "Declaring bad options and flags" do
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: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vollmer
@@ -9,17 +9,18 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-06-13 00:00:00 -07:00
12
+ date: 2008-07-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe
17
+ type: :development
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
20
21
  - - ">="
21
22
  - !ruby/object:Gem::Version
22
- version: 1.5.1
23
+ version: 1.7.0
23
24
  version:
24
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
26
  email:
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
60
  requirements: []
60
61
 
61
62
  rubyforge_project: clip
62
- rubygems_version: 1.1.1
63
+ rubygems_version: 1.2.0
63
64
  signing_key:
64
65
  specification_version: 2
65
66
  summary: Command-line parsing made short and sweet