colin 0.1.6 → 0.1.7
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.
- checksums.yaml +4 -4
- data/Gemfile +2 -3
- data/Rakefile +1 -10
- data/colin.gemspec +2 -2
- data/lib/colin.rb +4 -2
- data/spec/colin_spec.rb +103 -3
- data/spec/spec_helper.rb +5 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d65a626690660eca491e7dced7377a1055dfd46
|
4
|
+
data.tar.gz: 109919e6dbf5e8e2bd9830bcc0e6fd4a56c7b2ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffdd26b604cba21be846eafbfec8934ef30712c5624ba8414db10e61ce7b666fb0149c5669b6f2d5233a80afb3b0a2a9615fe31a7079a46f044701fc565965cd
|
7
|
+
data.tar.gz: aed85a2f8b7651547eac081d41a86174f8244c4c3769896aa49a2579a3f1c31a691524a1f161f64f0c0973acb4229a5129d8ba9b7b7862b6c7cf2e4b3d2be7ac
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,12 +1,3 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
|
3
|
-
|
4
|
-
arg_files = ENV["FILES"] && ENV["FILES"].split(/[\s,]+/)
|
5
|
-
all_files = Rake::FileList["./spec/**/*_spec.rb"]
|
6
|
-
files = arg_files || all_files
|
7
|
-
puts "\nRuning tests for: #{ files.join(" ") }\n\n"
|
8
|
-
|
9
|
-
system *["matest"].concat(files)
|
10
|
-
end
|
11
|
-
|
12
|
-
task :default => :test
|
3
|
+
require "matest/spec_tasks"
|
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.1.
|
7
|
+
spec.version = "0.1.7"
|
8
8
|
spec.authors = ["Federico Iachetti"]
|
9
9
|
spec.email = ["iachetti.federico@gmail.com"]
|
10
10
|
spec.summary = %q{COmmand Line INterface.}
|
@@ -19,5 +19,5 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.add_development_dependency "bundler", "~> 1.7"
|
21
21
|
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
-
spec.add_development_dependency "matest"
|
22
|
+
spec.add_development_dependency "matest"
|
23
23
|
end
|
data/lib/colin.rb
CHANGED
@@ -36,7 +36,7 @@ module Colin
|
|
36
36
|
def parse
|
37
37
|
(@args + [nil]).each do |opt|
|
38
38
|
case opt
|
39
|
-
when /^[\w
|
39
|
+
when /^[\w\/\.]+$/
|
40
40
|
if @current
|
41
41
|
set(@current, opt)
|
42
42
|
else
|
@@ -44,7 +44,7 @@ module Colin
|
|
44
44
|
end
|
45
45
|
when /^--([\w-]+)$/
|
46
46
|
keep($1)
|
47
|
-
when /^--([\w-]+)=([\w\s
|
47
|
+
when /^--([\w-]+)=([\w\s\/\.]+)$/
|
48
48
|
consume_current
|
49
49
|
set($1, $2)
|
50
50
|
when /^-(\w)([\w\/]+)$/
|
@@ -64,7 +64,9 @@ module Colin
|
|
64
64
|
def sanitize(value)
|
65
65
|
return true if value == "true"
|
66
66
|
return false if value == "false"
|
67
|
+
return nil if value == "nil" || value == "null"
|
67
68
|
return value.to_i if value =~ /^\d+$/
|
69
|
+
return value.to_f if value =~ /^\d+\.\d+$/
|
68
70
|
value
|
69
71
|
end
|
70
72
|
|
data/spec/colin_spec.rb
CHANGED
@@ -1,5 +1,105 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require "spec_helper"
|
2
|
+
require "colin"
|
3
|
+
|
4
|
+
def Parser(options={})
|
5
|
+
Colin::Parser.new(options)
|
6
|
+
end
|
7
|
+
|
8
|
+
scope Colin::Parser do
|
9
|
+
scope "#options" do
|
10
|
+
scope "empty array" do
|
11
|
+
let(:parser) { Parser([]) }
|
12
|
+
spec { parser.options == {} }
|
13
|
+
spec { parser.args == [] }
|
14
|
+
end
|
15
|
+
|
16
|
+
scope "unnamed attributes" do
|
17
|
+
let(:parser) { Parser( %w[first second] ) }
|
18
|
+
spec { parser.options == {} }
|
19
|
+
spec { parser.args == %w[first second] }
|
20
|
+
end
|
21
|
+
|
22
|
+
scope "double dashed attributes" do
|
23
|
+
scope "space" do
|
24
|
+
let(:parser) { Parser( %w[--name NAME] ) }
|
25
|
+
spec { parser.options == {name: "NAME"} }
|
26
|
+
spec { parser.args == [] }
|
27
|
+
end
|
28
|
+
|
29
|
+
scope "=" do
|
30
|
+
let(:parser) { Parser( %w[--name=NAME] ) }
|
31
|
+
spec { parser.options == {name: "NAME"} }
|
32
|
+
spec { parser.args == [] }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
scope "single dashed attributes" do
|
37
|
+
scope "space" do
|
38
|
+
let(:parser) { Parser( %w[-n NAME] ) }
|
39
|
+
spec { parser.options == {n: "NAME"} }
|
40
|
+
spec { parser.args == [] }
|
41
|
+
end
|
42
|
+
|
43
|
+
scope "=" do
|
44
|
+
let(:parser) { Parser( %w[-nNAME] ) }
|
45
|
+
spec { parser.options == {n: "NAME"} }
|
46
|
+
spec { parser.args == [] }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
scope "special types" do
|
51
|
+
spec "integer" do
|
52
|
+
@parser = Parser( %w[--number 78] )
|
53
|
+
@parser.options[:number] == 78
|
54
|
+
end
|
55
|
+
|
56
|
+
spec "float" do
|
57
|
+
@parser = Parser( %w[--number 5.1] )
|
58
|
+
@parser.options[:number] == 5.1
|
59
|
+
end
|
60
|
+
|
61
|
+
spec "true" do
|
62
|
+
@parser = Parser( %w[--flag true] )
|
63
|
+
@parser.options[:flag] == true
|
64
|
+
end
|
65
|
+
|
66
|
+
spec "false" do
|
67
|
+
@parser = Parser( %w[--flag false] )
|
68
|
+
@parser.options[:flag] == false
|
69
|
+
end
|
70
|
+
|
71
|
+
spec "nil" do
|
72
|
+
@parser = Parser( %w[--value nil] )
|
73
|
+
@parser.options[:value] == nil
|
74
|
+
end
|
75
|
+
|
76
|
+
spec "null" do
|
77
|
+
@parser = Parser( %w[--value null] )
|
78
|
+
@parser.options[:value] == nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
scope "flags" do
|
83
|
+
spec "dashed true" do
|
84
|
+
@parser = Parser( %w[-f] )
|
85
|
+
@parser.options[:f] == true
|
86
|
+
end
|
87
|
+
|
88
|
+
spec "double dashed true" do
|
89
|
+
@parser = Parser( %w[--flag] )
|
90
|
+
@parser.options[:flag] == true
|
91
|
+
end
|
92
|
+
|
93
|
+
spec "double dashed false" do
|
94
|
+
@parser = Parser( %w[--no-flag] )
|
95
|
+
@parser.options[:flag] == false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
scope "combination" do
|
100
|
+
let(:parser) { Parser( %w[some_file.rb -nNAME --age=34 -n 90 random_string --other_number 70] ) }
|
101
|
+
spec { parser.options == {n: "NAME", age: 34, n: 90, other_number: 70} }
|
102
|
+
spec { parser.args == %w[some_file.rb random_string] }
|
103
|
+
end
|
4
104
|
end
|
5
105
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Iachetti
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: matest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
description: COmmand Line INterface.
|
56
56
|
email:
|
57
57
|
- iachetti.federico@gmail.com
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- colin.gemspec
|
70
70
|
- lib/colin.rb
|
71
71
|
- spec/colin_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
72
73
|
homepage: https://github.com/iachettifederico/colin
|
73
74
|
licenses:
|
74
75
|
- MIT
|
@@ -95,3 +96,4 @@ specification_version: 4
|
|
95
96
|
summary: COmmand Line INterface.
|
96
97
|
test_files:
|
97
98
|
- spec/colin_spec.rb
|
99
|
+
- spec/spec_helper.rb
|