user_input 1.0.0 → 1.1.0

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -32,6 +32,8 @@ module UserInput
32
32
  attr_accessor :program_prefix
33
33
  # The banner to display above the help. Defaults to nil, in which case it's generated.
34
34
  attr_writer :banner
35
+ # Saved unknown barewords if save_unknown! is called, nil otherwise.
36
+ attr_reader :saved
35
37
 
36
38
  # If a block is passed in, it is given self.
37
39
  def initialize(program_prefix = $0)
@@ -39,6 +41,8 @@ module UserInput
39
41
  @order = []
40
42
  @program_prefix = program_prefix
41
43
  @banner = nil
44
+
45
+ @saved = nil
42
46
 
43
47
  if (block_given?)
44
48
  yield self
@@ -73,6 +77,13 @@ module UserInput
73
77
  return self
74
78
  end
75
79
  private :define_value
80
+
81
+ # Enable saving of unknown barewords. With this, the only way to terminate
82
+ # parsing is to hit the end of the parse or with --.
83
+ # You can retrieve the saved words from #saved.
84
+ def save_unknown!
85
+ @saved = []
86
+ end
76
87
 
77
88
  # This defines a command line argument that takes a value.
78
89
  def argument(short_name, long_name, description, default_value, validate = nil, &block)
@@ -132,8 +143,15 @@ module UserInput
132
143
  end
133
144
  }
134
145
  else
135
- # unrecognized bareword, so bail out and leave it to the caller to figure it out.
136
- return self
146
+ # unrecognized bareword (not part of a flag). What we do
147
+ # depends on whether or not we're saving unknown barewords.
148
+ if (@saved)
149
+ #save it
150
+ @saved << arg
151
+ else
152
+ # bail out and leave it to the caller to figure it out.
153
+ return self
154
+ end
137
155
  end
138
156
  end
139
157
 
@@ -151,6 +151,18 @@ describe UserInput::OptionParser do
151
151
  arr.should == ["whatever"]
152
152
  end
153
153
 
154
+ it "should save unknown barewords if you tell it to, and should continue parsing" do
155
+ @opt.save_unknown!
156
+
157
+ arr = ["-a", "boom", "-c", "blorp", "blah"]
158
+ @opt.parse!(arr)
159
+ arr.should == []
160
+ @opt.saved.should == ["boom", "blah"]
161
+
162
+ @opt.abba?.should be_true
163
+ @opt.cool.should == "blorp"
164
+ end
165
+
154
166
  it "should return a string from to_s" do
155
167
  # Possibly this spec should include an example to compare against, but that seems too rigid.
156
168
  @opt.to_s.should be_kind_of(String)
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: user_input
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Graham Batty
@@ -9,19 +15,25 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-02-04 00:00:00 -07:00
18
+ date: 2010-12-15 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
23
34
  version: 1.2.9
24
- version:
35
+ type: :development
36
+ version_requirements: *id001
25
37
  description: Provides simple, convention-based, user input validation and coercion. Also provides a 'type safe hash' and command line option parser that use it.
26
38
  email: graham@stormbrew.ca
27
39
  executables: []
@@ -33,7 +45,6 @@ extra_rdoc_files:
33
45
  - README.rdoc
34
46
  files:
35
47
  - .document
36
- - .gitignore
37
48
  - LICENSE
38
49
  - README.rdoc
39
50
  - Rakefile
@@ -51,26 +62,32 @@ homepage: http://github.com/stormbrew/user_input
51
62
  licenses: []
52
63
 
53
64
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
65
+ rdoc_options: []
66
+
56
67
  require_paths:
57
68
  - lib
58
69
  required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
59
71
  requirements:
60
72
  - - ">="
61
73
  - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
62
77
  version: "0"
63
- version:
64
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
65
80
  requirements:
66
81
  - - ">="
67
82
  - !ruby/object:Gem::Version
83
+ hash: 3
84
+ segments:
85
+ - 0
68
86
  version: "0"
69
- version:
70
87
  requirements: []
71
88
 
72
89
  rubyforge_project:
73
- rubygems_version: 1.3.5
90
+ rubygems_version: 1.3.7
74
91
  signing_key:
75
92
  specification_version: 3
76
93
  summary: Provides simple, convention-based, user input validation and coercion. Also provides a 'type safe hash' and command line option parser that use it.
data/.gitignore DELETED
@@ -1,22 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
- *.gemspec
21
-
22
- ## PROJECT::SPECIFIC