slop 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/slop.rb +8 -3
- data/spec/slop_spec.rb +14 -0
- metadata +3 -3
data/lib/slop.rb
CHANGED
@@ -5,7 +5,7 @@ require 'slop/option'
|
|
5
5
|
class Slop
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
VERSION = '0.1.
|
8
|
+
VERSION = '0.1.8'
|
9
9
|
|
10
10
|
# Raised when an option expects an argument and none is given
|
11
11
|
class MissingArgumentError < ArgumentError; end
|
@@ -152,8 +152,13 @@ class Slop
|
|
152
152
|
private
|
153
153
|
|
154
154
|
def flag_or_option?(flag)
|
155
|
-
return unless flag
|
156
|
-
|
155
|
+
return unless flag && flag.size > 1
|
156
|
+
|
157
|
+
if flag[1] == '-'
|
158
|
+
return flag[0] == '-' && flag[3]
|
159
|
+
elsif flag[0] == '-'
|
160
|
+
return !flag[3]
|
161
|
+
end
|
157
162
|
end
|
158
163
|
|
159
164
|
def pad_options(args)
|
data/spec/slop_spec.rb
CHANGED
@@ -108,6 +108,11 @@ describe Slop do
|
|
108
108
|
it "does not require argument to be true if optional is true" do
|
109
109
|
Slop.parse("--name Lee") { opt :name, :optional => true }.value_for(:name).should == "Lee"
|
110
110
|
end
|
111
|
+
|
112
|
+
it "responds to both long options and single character flags" do
|
113
|
+
Slop.parse("--name Lee") { opt :name, true }[:name].should == "Lee"
|
114
|
+
Slop.parse("-n Lee") { opt :n, :name, true }[:name].should == "Lee"
|
115
|
+
end
|
111
116
|
end
|
112
117
|
|
113
118
|
describe "options" do
|
@@ -145,4 +150,13 @@ describe Slop do
|
|
145
150
|
end
|
146
151
|
end
|
147
152
|
|
153
|
+
describe "flag_or_option?" do
|
154
|
+
it "should be true if the string is a flag or an option" do
|
155
|
+
good = ["-f", "--flag"]
|
156
|
+
bad = ["-flag", "f", "flag", "f-lag", "flag-", "--", "-"]
|
157
|
+
good.each {|g| @slop.send(:flag_or_option?, g).should be_true }
|
158
|
+
bad.each {|b| @slop.send(:flag_or_option?, b).should be_false }
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
148
162
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lee Jarvis
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: 2.1.0
|
33
33
|
type: :development
|
34
34
|
version_requirements: *id001
|
35
|
-
description:
|
35
|
+
description: A simple DSL for gathering options and parsing the command line
|
36
36
|
email: lee@jarvis.co
|
37
37
|
executables: []
|
38
38
|
|