cli-parser 0.0.2 → 0.0.3
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/lib/cli-parser.rb +2 -2
- data/test/manual_test.rb +9 -0
- data/test/test-cli-parser.rb +17 -2
- 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: a26752a93198472cd4b0993ef9e23de77dd09294
|
4
|
+
data.tar.gz: 80fd5ca71bfa47386e2310cfc8512f78bb86f0b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7593106ae9dabb313d73221cb9958596ef7e4443d264cac151bb7ba36e62bc866dc189c35afa2f9ef3b8e9fcb75cce5c2ad9a1d0c6dc7e2c215fd24074b00d76
|
7
|
+
data.tar.gz: 099ba5ef6b5ad88ac70a55d50aec4b5cb9d861c6f8186db1b782b65621dbcc730ee01a4b4243ab627592456425e988c0c0010ac24f60d5304e397788d6149dd6
|
data/lib/cli-parser.rb
CHANGED
@@ -7,8 +7,8 @@ module CliParser
|
|
7
7
|
result_opts = {}
|
8
8
|
|
9
9
|
keywords = %w("[^"]*" [^\s-][^\s]+)
|
10
|
-
keywords << flags.collect { | f | Regexp.quote(f) }.join('|')
|
11
|
-
keywords << options.collect { | o | Regexp.quote(o) + '\s+([^\s"]+|"[^"]*")+' }.join('|')
|
10
|
+
keywords << flags.collect { | f | Regexp.quote(f) }.join('|') unless flags.empty?
|
11
|
+
keywords << options.collect { | o | Regexp.quote(o) + '\s+([^\s"]+|"[^"]*")+' }.join('|') unless options.empty?
|
12
12
|
regex = Regexp.new('(' + keywords.compact.join('|') + ')')
|
13
13
|
|
14
14
|
cmd.scan(regex).each { | a |
|
data/test/manual_test.rb
ADDED
data/test/test-cli-parser.rb
CHANGED
@@ -7,16 +7,31 @@ module CliParserTest
|
|
7
7
|
|
8
8
|
#noinspection RubyStringKeysInHashInspection
|
9
9
|
def test_parse
|
10
|
+
|
11
|
+
cmd = 'test1 test2 test3'
|
12
|
+
args, options = CliParser.parse([], [], cmd)
|
13
|
+
assert_equal(%w(test1 test2 test3), args)
|
14
|
+
assert_equal({}, options)
|
15
|
+
|
16
|
+
|
10
17
|
cmd = '-w arg1 -o Test arg2 -t "Hello World" arg3'
|
11
18
|
|
12
19
|
args, options = CliParser.parse(%w(-w), %w(-o -t), cmd)
|
13
20
|
assert_equal(%w(arg1 arg2 arg3), args)
|
14
21
|
assert_equal({ '-w' => true, '-o' => 'Test', '-t' => 'Hello World' }, options)
|
15
22
|
|
16
|
-
|
23
|
+
args, options = CliParser.parse([], %w(-o -t), cmd)
|
24
|
+
assert_equal(%w(arg1 arg2 arg3), args)
|
25
|
+
assert_equal({'-o' => 'Test', '-t' => 'Hello World' }, options)
|
26
|
+
|
27
|
+
args, options = CliParser.parse(%w(-w), [], cmd)
|
28
|
+
assert_equal(['arg1', 'Test', 'arg2', '"Hello World"', 'arg3'], args)
|
29
|
+
assert_equal({'-w' => true }, options)
|
30
|
+
|
17
31
|
args, options = CliParser.parse([], [], cmd)
|
18
|
-
assert_equal(
|
32
|
+
assert_equal(['arg1', 'Test', 'arg2', '"Hello World"', 'arg3'], args)
|
19
33
|
assert_equal({}, options)
|
34
|
+
|
20
35
|
end
|
21
36
|
|
22
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taco Jan Osinga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A command-line parser. Extracts arguments, switches and options.
|
14
14
|
email: info@osingasoftware.nl
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- LICENSE
|
20
20
|
- lib/cli-parser.rb
|
21
|
+
- test/manual_test.rb
|
21
22
|
- test/test-cli-parser.rb
|
22
23
|
homepage: https://github.com/tjosinga/cli-parser
|
23
24
|
licenses:
|
@@ -44,4 +45,5 @@ signing_key:
|
|
44
45
|
specification_version: 4
|
45
46
|
summary: CLI Parser
|
46
47
|
test_files:
|
48
|
+
- test/manual_test.rb
|
47
49
|
- test/test-cli-parser.rb
|