colin 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/colin +14 -0
- data/colin.gemspec +1 -1
- data/lib/colin.rb +63 -61
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 01f97b1a0a56d99c382e508500823fab7eb354ee
|
4
|
+
data.tar.gz: 23f7158cf952eb7f7e0a50593188ab29a4f7a50d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b0cc42eee6e22ecde5e7ddb84adb448ca02ff0d855f945bb8caa2c671a7a32685e26529543c5b8cfbd66bc4f7b2afc885ae7ab50bb46cf7823623e86c481a4
|
7
|
+
data.tar.gz: 4813ff41c0644b8b79bec9d3b689fd5257583b58fd45299372acf6f5195b1e8276ded646b2b4340e20e19af2fd0a22b603ea7c551c1193436e33638e9dce08c4
|
data/bin/colin
ADDED
data/colin.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "colin"
|
7
|
-
spec.version = "0.0
|
7
|
+
spec.version = "0.1.0"
|
8
8
|
spec.authors = ["Federico Iachetti"]
|
9
9
|
spec.email = ["iachetti.federico@gmail.com"]
|
10
10
|
spec.summary = %q{COmmand Line INterface.}
|
data/lib/colin.rb
CHANGED
@@ -1,79 +1,81 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Colin
|
2
|
+
class Parser
|
3
|
+
def initialize(args=[])
|
4
|
+
@args = args
|
5
|
+
@options = {}
|
6
|
+
@skipped = []
|
7
|
+
parse
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
def options
|
11
|
+
@options
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
def args
|
15
|
+
@skipped
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
+
private
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
def parse
|
21
|
+
(@args + [nil]).each do |opt|
|
22
|
+
case opt
|
23
|
+
when /^\w+$/
|
24
|
+
if @current
|
25
|
+
set(@current, opt)
|
26
|
+
else
|
27
|
+
skip(opt)
|
28
|
+
end
|
29
|
+
when /^--([\w-]+)$/
|
30
|
+
keep($1)
|
31
|
+
when /^--([\w-]+)=([\w\s]+)$/
|
32
|
+
consume_current
|
33
|
+
set($1, $2)
|
34
|
+
when /^-(\w)(\w+)$/
|
35
|
+
consume_current
|
36
|
+
set($1, $2)
|
37
|
+
when /^-(\w)$/
|
38
|
+
consume_current
|
39
|
+
keep($1)
|
40
|
+
when nil
|
41
|
+
consume_current
|
25
42
|
else
|
26
43
|
skip(opt)
|
27
44
|
end
|
28
|
-
when /^--([\w-]+)$/
|
29
|
-
keep($1)
|
30
|
-
when /^--([\w-]+)=([\w\s]+)$/
|
31
|
-
consume_current
|
32
|
-
set($1, $2)
|
33
|
-
when /^-(\w)(\w+)$/
|
34
|
-
consume_current
|
35
|
-
set($1, $2)
|
36
|
-
when /^-(\w)$/
|
37
|
-
consume_current
|
38
|
-
keep($1)
|
39
|
-
when nil
|
40
|
-
consume_current
|
41
|
-
else
|
42
|
-
skip(opt)
|
43
45
|
end
|
44
46
|
end
|
45
|
-
end
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def sanitize(value)
|
49
|
+
return true if value == "true"
|
50
|
+
return false if value == "false"
|
51
|
+
return value.to_i if value =~ /^\d+$/
|
52
|
+
value
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
def set(key, value)
|
56
|
+
@options[key.to_sym] = sanitize(value)
|
57
|
+
@current = nil if @current
|
58
|
+
end
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
def keep(opt)
|
61
|
+
@current = opt
|
62
|
+
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
64
|
+
def skip(opt)
|
65
|
+
@skipped << opt
|
66
|
+
end
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
68
|
+
def consume_current
|
69
|
+
if @current
|
70
|
+
if @current =~ /^no-(.+)/
|
71
|
+
key = $1
|
72
|
+
value = false
|
73
|
+
else
|
74
|
+
key = @current
|
75
|
+
value = true
|
76
|
+
end
|
77
|
+
set(key, value)
|
75
78
|
end
|
76
|
-
set(key, value)
|
77
79
|
end
|
78
80
|
end
|
79
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: COmmand Line INterface.
|
56
56
|
email:
|
57
57
|
- iachetti.federico@gmail.com
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- colin
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
68
|
+
- bin/colin
|
67
69
|
- colin.gemspec
|
68
70
|
- lib/colin.rb
|
69
71
|
- spec/colin_spec.rb
|