args_parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/README.rdoc +6 -0
- data/lib/args_parser/parser.rb +3 -1
- data/lib/args_parser.rb +1 -1
- data/test/test_args_parser.rb +15 -3
- data/test/test_helper.rb +1 -0
- metadata +73 -59
data/History.txt
CHANGED
data/README.rdoc
CHANGED
data/lib/args_parser/parser.rb
CHANGED
@@ -62,6 +62,8 @@ module ArgsParser
|
|
62
62
|
k = arg.scan(/^-+([^-\s]+)$/)[0][0].strip.to_sym
|
63
63
|
k = aliases[k] if aliases[k]
|
64
64
|
else
|
65
|
+
arg = arg.to_i if arg =~ /^\d+$/
|
66
|
+
arg = arg.to_f if arg =~ /^\d+\.\d+$/
|
65
67
|
params[k][:value] = arg
|
66
68
|
k = nil
|
67
69
|
end
|
@@ -89,7 +91,7 @@ module ArgsParser
|
|
89
91
|
def has_param?(*param_)
|
90
92
|
!(param_.flatten.map{|i|
|
91
93
|
v = self[i]
|
92
|
-
(v and
|
94
|
+
(v and [String, Fixnum, Float].include? v.class) ? true : false
|
93
95
|
}.include? false)
|
94
96
|
end
|
95
97
|
|
data/lib/args_parser.rb
CHANGED
data/test/test_args_parser.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/test_helper.rb'
|
|
2
2
|
|
3
3
|
class TestArgsParser < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
@argv = 'test --input ~/tmp -a --o ./out -h'.split(/\s+/)
|
5
|
+
@argv = 'test --input ~/tmp -a --o ./out -h --depth 030 --pi 3.14'.split(/\s+/)
|
6
6
|
@parser = ArgsParser.parse @argv do
|
7
7
|
arg :input, 'input dir', :alias => :i
|
8
8
|
arg :output, 'output dir', :alias => :o
|
@@ -22,8 +22,18 @@ class TestArgsParser < Test::Unit::TestCase
|
|
22
22
|
assert @parser[:output] == './out'
|
23
23
|
end
|
24
24
|
|
25
|
+
def test_cast_integer
|
26
|
+
assert @parser[:depth] == 30
|
27
|
+
assert @parser[:depth].class == Fixnum
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_cast_float
|
31
|
+
assert @parser[:pi] == 3.14
|
32
|
+
assert @parser[:pi].class == Float
|
33
|
+
end
|
34
|
+
|
25
35
|
def test_missing_arg
|
26
|
-
assert @parser[:
|
36
|
+
assert @parser[:b] != true
|
27
37
|
end
|
28
38
|
|
29
39
|
def test_switch
|
@@ -33,10 +43,12 @@ class TestArgsParser < Test::Unit::TestCase
|
|
33
43
|
def test_has_param?
|
34
44
|
assert @parser.has_param? :input
|
35
45
|
assert @parser.has_param? :output
|
46
|
+
assert @parser.has_param? :depth
|
47
|
+
assert @parser.has_param? :pi
|
36
48
|
end
|
37
49
|
|
38
50
|
def test_has_params?
|
39
|
-
assert @parser.has_param? :input, :output
|
51
|
+
assert @parser.has_param? :input, :output, :depth, :pi
|
40
52
|
end
|
41
53
|
|
42
54
|
def test_has_not_param?
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,74 +1,80 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: args_parser
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Sho Hashimoto
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '3.10'
|
22
|
-
type: :development
|
17
|
+
|
18
|
+
date: 2012-09-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
23
21
|
prerelease: false
|
24
|
-
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
|
-
requirements:
|
24
|
+
requirements:
|
27
25
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
requirements:
|
35
|
-
- - ! '>='
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 1.5.3
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 19
|
28
|
+
segments:
|
29
|
+
- 3
|
30
|
+
- 10
|
31
|
+
version: "3.10"
|
38
32
|
type: :development
|
33
|
+
name: rdoc
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
39
36
|
prerelease: false
|
40
|
-
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
38
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 5
|
43
|
+
segments:
|
44
|
+
- 1
|
45
|
+
- 5
|
46
|
+
- 3
|
45
47
|
version: 1.5.3
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: hoe
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.0'
|
54
48
|
type: :development
|
49
|
+
name: newgem
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
55
52
|
prerelease: false
|
56
|
-
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
54
|
none: false
|
58
|
-
requirements:
|
55
|
+
requirements:
|
59
56
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 5
|
59
|
+
segments:
|
60
|
+
- 3
|
61
|
+
- 1
|
62
|
+
version: "3.1"
|
63
|
+
type: :development
|
64
|
+
name: hoe
|
65
|
+
version_requirements: *id003
|
62
66
|
description: ARGV parser - Parse args from command line.
|
63
|
-
email:
|
67
|
+
email:
|
64
68
|
- hashimoto@shokai.org
|
65
69
|
executables: []
|
70
|
+
|
66
71
|
extensions: []
|
67
|
-
|
72
|
+
|
73
|
+
extra_rdoc_files:
|
68
74
|
- History.txt
|
69
75
|
- Manifest.txt
|
70
76
|
- README.rdoc
|
71
|
-
files:
|
77
|
+
files:
|
72
78
|
- History.txt
|
73
79
|
- Manifest.txt
|
74
80
|
- README.rdoc
|
@@ -84,30 +90,38 @@ files:
|
|
84
90
|
- .gemtest
|
85
91
|
homepage: http://github.com/shokai/args_parser
|
86
92
|
licenses: []
|
93
|
+
|
87
94
|
post_install_message:
|
88
|
-
rdoc_options:
|
95
|
+
rdoc_options:
|
89
96
|
- --main
|
90
97
|
- README.rdoc
|
91
|
-
require_paths:
|
98
|
+
require_paths:
|
92
99
|
- lib
|
93
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
101
|
none: false
|
95
|
-
requirements:
|
96
|
-
- -
|
97
|
-
- !ruby/object:Gem::Version
|
98
|
-
|
99
|
-
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
110
|
none: false
|
101
|
-
requirements:
|
102
|
-
- -
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
105
118
|
requirements: []
|
119
|
+
|
106
120
|
rubyforge_project: args_parser
|
107
121
|
rubygems_version: 1.8.24
|
108
122
|
signing_key:
|
109
123
|
specification_version: 3
|
110
124
|
summary: ARGV parser - Parse args from command line.
|
111
|
-
test_files:
|
125
|
+
test_files:
|
112
126
|
- test/test_args_parser.rb
|
113
127
|
- test/test_helper.rb
|