minimist 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -8
- data/lib/minimist.rb +16 -10
- data/lib/minimist/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7fb0a6d33c9ccc2e3cd68322628d29bc645d22c
|
4
|
+
data.tar.gz: 62cb29826e6e208ad0a1269d31cb914f37a675cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eb9b785e24a770b3c1a98f217b8e09a454e4d77ac024269a876584934842eb489656649e038a111e83861c847468f975957b9b507143e9c35929bb2e5dab02e
|
7
|
+
data.tar.gz: e404dd665e0d43c0abfa6eca42665354e2ffce7ac0dfd0b28f5a3af75aac908db8c84884bb36a91070c80a7f8dcce96ecaa93cce701743bee2492d288194a1d8
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Minimist
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A tiny ruby ARGV parser.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,16 +20,34 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
This isn't designed to be as fully featured as things like OptionParser and Trollop.
|
24
|
+
I just wanted to get at cli arguments without having to use a fully-featured DSL to specify
|
25
|
+
exactly what I needed.
|
28
26
|
|
29
|
-
|
27
|
+
It accepts a string array and returns a hash containing commands and options.
|
30
28
|
|
31
|
-
|
29
|
+
```ruby
|
30
|
+
Minimist.parse("parse this --with=2 -asbd -n4 --no-changes --send two".split(" "))
|
31
|
+
|
32
|
+
=> {
|
33
|
+
:commands=>["parse", "this"],
|
34
|
+
:options=> {
|
35
|
+
:with=>"2",
|
36
|
+
:a=>true,
|
37
|
+
:s=>true,
|
38
|
+
:b=>true,
|
39
|
+
:d=>true,
|
40
|
+
:n=>"4",
|
41
|
+
:changes=>false,
|
42
|
+
:send=>"two"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
```
|
32
46
|
|
33
47
|
## Contributing
|
34
48
|
|
49
|
+
Create a pr discussing your change and make sure to add a test for your feature :)
|
50
|
+
|
35
51
|
1. Fork it ( https://github.com/[my-github-username]/minimist/fork )
|
36
52
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
53
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/lib/minimist.rb
CHANGED
@@ -7,8 +7,8 @@ module Minimist
|
|
7
7
|
class << self
|
8
8
|
REGEX = {
|
9
9
|
command: /^[A-Za-z]/,
|
10
|
-
double_dash: /^--.+/,
|
11
10
|
double_dash_negation: /^--no-.+/,
|
11
|
+
double_dash: /^--.+/,
|
12
12
|
single_dash: /^-[^-]+/
|
13
13
|
}
|
14
14
|
|
@@ -49,8 +49,6 @@ module Minimist
|
|
49
49
|
# to skip the next value or not
|
50
50
|
#
|
51
51
|
out, skip = send(type, arg, i, out)
|
52
|
-
|
53
|
-
puts "#{i} #{arg} #{type} - should skip #{skip}"
|
54
52
|
end
|
55
53
|
|
56
54
|
out
|
@@ -67,6 +65,8 @@ module Minimist
|
|
67
65
|
# If the next command is
|
68
66
|
#
|
69
67
|
def single_dash(arg, index, argv_object)
|
68
|
+
should_skip = false
|
69
|
+
|
70
70
|
#
|
71
71
|
# match -abc, -n5 arg types
|
72
72
|
#
|
@@ -89,25 +89,31 @@ module Minimist
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def double_dash(arg, index, argv_object)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
match_data = arg.match(/^--([A-Za-z]*-?[A-Za-z]?*)=?([A-Za-z0-9]*)/)
|
92
|
+
match_data = arg.match(/^--([A-Za-z]*-?[A-Za-z]*)=?([A-Za-z0-9]*)/)
|
93
|
+
val = true
|
94
|
+
should_skip = false
|
96
95
|
|
97
96
|
if !match_data[2].empty?
|
98
97
|
argv_object[:options][match_data[1].to_sym] = try_convert(match_data[2])
|
99
98
|
else
|
100
|
-
|
99
|
+
val = true
|
100
|
+
|
101
|
+
if @argv[index + 1] =~ REGEX[:command]
|
102
|
+
val = @argv[index + 1]
|
103
|
+
should_skip = true
|
104
|
+
end
|
105
|
+
|
106
|
+
argv_object[:options][match_data[1].to_sym] = val
|
101
107
|
end
|
102
108
|
|
103
|
-
[argv_object,
|
109
|
+
[argv_object, should_skip]
|
104
110
|
end
|
105
111
|
|
106
112
|
def double_dash_negation(arg, index, argv_object)
|
107
113
|
#
|
108
114
|
# regex matvch --no-val into val = true
|
109
115
|
#
|
110
|
-
match_data = arg.match(/^--no-([A-Za-z]*-?[A-Za-z]
|
116
|
+
match_data = arg.match(/^--no-([A-Za-z]*-?[A-Za-z]*)/)
|
111
117
|
argv_object[:options][match_data[1].to_sym] = false
|
112
118
|
|
113
119
|
[argv_object, false]
|
data/lib/minimist/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minimist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Connor Atherton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|