cli 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/VERSION +1 -1
- data/cli.gemspec +1 -1
- data/lib/cli/dsl.rb +2 -2
- data/spec/argument_spec.rb +16 -0
- data/spec/option_spec.rb +17 -1
- metadata +16 -16
data/README.md
CHANGED
@@ -391,7 +391,7 @@ In addition to *switch*, option hash can have following pairs:
|
|
391
391
|
* **:default => value** - use default value of *value* if the option was not specified on the command argument list. The *value* will firstly be casted to string (with `#to_s`) and then it will be casted if casting is specified.
|
392
392
|
* **:default_label => label** - display *label* in usage rather than default value - useful to descirbe default value if default value is generated if no value is provided
|
393
393
|
* **:cast => cast specifier** - cast the provided value (or default) with given *cast specifier*.
|
394
|
-
The specifier can be a class constant
|
394
|
+
The specifier can be a class constant - the value will be provided to `#new` method of the class and resulting object used as option value. When provided constant does not respond to `#new` (i.e. it is a module) the `#load` method will be tried instead. If provided specifier is a Proc (or `lambda {}`) the Proc will be called with the value and resulting value will be used. Otherwise `CLI::ParsingError::CastError` will be raised. Special cast specified `Integer` or `Float` can also be used - the value will be strictly casted to integer or float type.
|
395
395
|
* **:required => true** - if used and no *default* value is specified the `#parse` method will fail with `CLI::ParsingError::MissingOptionValueError` if the option was not specified in the command argument list. If `#parse!` method was used the program will exit with appropriate message.
|
396
396
|
|
397
397
|
#### options :name [, options hash]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/cli.gemspec
CHANGED
data/lib/cli/dsl.rb
CHANGED
@@ -19,9 +19,9 @@ class CLI
|
|
19
19
|
|
20
20
|
if cast_to.is_a? Module # all classes are modules
|
21
21
|
if cast_to == Integer
|
22
|
-
value
|
22
|
+
Integer(value)
|
23
23
|
elsif cast_to == Float
|
24
|
-
value
|
24
|
+
Float(value)
|
25
25
|
elsif cast_to.respond_to? :new
|
26
26
|
cast_to.new(value)
|
27
27
|
elsif cast_to.respond_to? :load
|
data/spec/argument_spec.rb
CHANGED
@@ -32,6 +32,22 @@ describe CLI do
|
|
32
32
|
ps.number.should == 123.0
|
33
33
|
end
|
34
34
|
|
35
|
+
it "casting should fail if not proper integer given" do
|
36
|
+
lambda {
|
37
|
+
ps = CLI.new do
|
38
|
+
argument :size, :cast => Integer
|
39
|
+
end.parse(['24.99'])
|
40
|
+
}.should raise_error(CLI::ParsingError::CastError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "casting should fail if not proper float given" do
|
44
|
+
lambda {
|
45
|
+
ps = CLI.new do
|
46
|
+
argument :size, :cast => Float
|
47
|
+
end.parse(['24.99x'])
|
48
|
+
}.should raise_error(CLI::ParsingError::CastError)
|
49
|
+
end
|
50
|
+
|
35
51
|
it "should cast default value" do
|
36
52
|
ps = CLI.new do
|
37
53
|
argument :number, :cast => Integer, :default => '123'
|
data/spec/option_spec.rb
CHANGED
@@ -26,6 +26,22 @@ describe CLI do
|
|
26
26
|
ps.size.should == 24
|
27
27
|
end
|
28
28
|
|
29
|
+
it "casting should fail if not proper integer given" do
|
30
|
+
lambda {
|
31
|
+
ps = CLI.new do
|
32
|
+
option :size, :cast => Integer
|
33
|
+
end.parse(['--size', '24.99'])
|
34
|
+
}.should raise_error(CLI::ParsingError::CastError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "casting should fail if not proper float given" do
|
38
|
+
lambda {
|
39
|
+
ps = CLI.new do
|
40
|
+
option :size, :cast => Float
|
41
|
+
end.parse(['--size', '24.99x'])
|
42
|
+
}.should raise_error(CLI::ParsingError::CastError)
|
43
|
+
end
|
44
|
+
|
29
45
|
it "should support casting of multiple options" do
|
30
46
|
ps = CLI.new do
|
31
47
|
options :size, :cast => Integer
|
@@ -86,7 +102,7 @@ describe CLI do
|
|
86
102
|
it "default value is casted" do
|
87
103
|
ps = CLI.new do
|
88
104
|
option :location, :default => 'singapore'
|
89
|
-
option :size, :cast => Integer, :default => 23
|
105
|
+
option :size, :cast => Integer, :default => 23
|
90
106
|
end.parse([])
|
91
107
|
ps.location.should be_a String
|
92
108
|
ps.location.should == 'singapore'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-11-11 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70249594753380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '2.4'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70249594753380
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cucumber
|
27
|
-
requirement: &
|
27
|
+
requirement: &70249594752900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70249594752900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70249594752320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '1.2'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70249594752320
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &70249594751660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.6.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70249594751660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rcov
|
60
|
-
requirement: &
|
60
|
+
requirement: &70249594751120 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70249594751120
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdoc
|
71
|
-
requirement: &
|
71
|
+
requirement: &70249594750500 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '3.9'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70249594750500
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: ruby-ip
|
82
|
-
requirement: &
|
82
|
+
requirement: &70249594750020 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0.9'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70249594750020
|
91
91
|
description: Command Line Interface gem allows you to quickly specify command argument
|
92
92
|
parser that will automatically generate usage, handle stdin, switches, options and
|
93
93
|
arguments with default values and value casting
|
@@ -143,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
143
143
|
version: '0'
|
144
144
|
segments:
|
145
145
|
- 0
|
146
|
-
hash:
|
146
|
+
hash: 2443358638840763179
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
none: false
|
149
149
|
requirements:
|