colin 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/colin +14 -0
  3. data/colin.gemspec +1 -1
  4. data/lib/colin.rb +63 -61
  5. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a74b66dd3fd1eaab76cacdf9ba57899d96ca39f
4
- data.tar.gz: 9807710589da18d28df3197c46207c1d21ec5a92
3
+ metadata.gz: 01f97b1a0a56d99c382e508500823fab7eb354ee
4
+ data.tar.gz: 23f7158cf952eb7f7e0a50593188ab29a4f7a50d
5
5
  SHA512:
6
- metadata.gz: 9c3bed7d3e77716dd6149e10f1958ea67df7d265335d284a41baac762428f63c7f72c3a8e151add6ece7b059924e9ead482977a1eba1ab950599e5aa3b321769
7
- data.tar.gz: b08b3f6a28c6fe567ed197a1afa2a2813f19339740f50c4ac41b340b9fe555b843ee95419bc9cdcca12becdfc04b4dc8152bc468d5c48609b57e9db65750d147
6
+ metadata.gz: 72b0cc42eee6e22ecde5e7ddb84adb448ca02ff0d855f945bb8caa2c671a7a32685e26529543c5b8cfbd66bc4f7b2afc885ae7ab50bb46cf7823623e86c481a4
7
+ data.tar.gz: 4813ff41c0644b8b79bec9d3b689fd5257583b58fd45299372acf6f5195b1e8276ded646b2b4340e20e19af2fd0a22b603ea7c551c1193436e33638e9dce08c4
data/bin/colin ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path("../../lib", __FILE__))
3
+
4
+ require "colin"
5
+
6
+ require "pp"
7
+ cli = Colin::Parser.new(ARGV)
8
+
9
+ puts "# Options:"
10
+ pp cli.options
11
+ puts
12
+ puts "# Remaining arguments:"
13
+ pp cli.args
14
+
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.2"
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
- class Colin
2
- def initialize(args=[])
3
- @args = args
4
- @options = {}
5
- @skipped = []
6
- parse
7
- end
1
+ module Colin
2
+ class Parser
3
+ def initialize(args=[])
4
+ @args = args
5
+ @options = {}
6
+ @skipped = []
7
+ parse
8
+ end
8
9
 
9
- def options
10
- @options
11
- end
10
+ def options
11
+ @options
12
+ end
12
13
 
13
- def args
14
- @skipped
15
- end
14
+ def args
15
+ @skipped
16
+ end
16
17
 
17
- private
18
+ private
18
19
 
19
- def parse
20
- (@args + [nil]).each do |opt|
21
- case opt
22
- when /^\w+$/
23
- if @current
24
- set(@current, opt)
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
- def sanitize(value)
48
- return true if value == "true"
49
- return false if value == "false"
50
- return value.to_i if value =~ /^\d+$/
51
- value
52
- end
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
- def set(key, value)
55
- @options[key.to_sym] = sanitize(value)
56
- @current = nil if @current
57
- end
55
+ def set(key, value)
56
+ @options[key.to_sym] = sanitize(value)
57
+ @current = nil if @current
58
+ end
58
59
 
59
- def keep(opt)
60
- @current = opt
61
- end
60
+ def keep(opt)
61
+ @current = opt
62
+ end
62
63
 
63
- def skip(opt)
64
- @skipped << opt
65
- end
64
+ def skip(opt)
65
+ @skipped << opt
66
+ end
66
67
 
67
- def consume_current
68
- if @current
69
- if @current =~ /^no-(.+)/
70
- key = $1
71
- value = false
72
- else
73
- key = @current
74
- value = true
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.2
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