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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f46baa494ac45ec68b037ae8575060c88efc6dcb
4
- data.tar.gz: 8a534b47ddc3bb831f43359b68bd5c1ff437dbe3
3
+ metadata.gz: a26752a93198472cd4b0993ef9e23de77dd09294
4
+ data.tar.gz: 80fd5ca71bfa47386e2310cfc8512f78bb86f0b5
5
5
  SHA512:
6
- metadata.gz: 9baf45f4a0936b4bd57829106f65e58033147b64b42433c88ea6d0e9a087c2d262bc790d5a83e0f118f153c69cafd10466f511299946776754491aff9cbae47f
7
- data.tar.gz: 8077f765c9a7f6480790cc98a46b09affaff860ce003ea54a78770a71c5bec75a141a0174cfa4d3d491efe03c596ee43fbba34b421abe7f99bd2e5215076f6a0
6
+ metadata.gz: 7593106ae9dabb313d73221cb9958596ef7e4443d264cac151bb7ba36e62bc866dc189c35afa2f9ef3b8e9fcb75cce5c2ad9a1d0c6dc7e2c215fd24074b00d76
7
+ data.tar.gz: 099ba5ef6b5ad88ac70a55d50aec4b5cb9d861c6f8186db1b782b65621dbcc730ee01a4b4243ab627592456425e988c0c0010ac24f60d5304e397788d6149dd6
@@ -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 |
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require '../lib/cli-parser'
4
+ require 'json'
5
+
6
+ arguments, options = CliParser.parse(%w(-w), %w(-o -t))
7
+
8
+ puts 'Arguments: ' + JSON.pretty_generate(arguments)
9
+ puts 'Options: ' + JSON.pretty_generate(options)
@@ -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
- cmd = 'test1 test2 test3'
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(%w(test1 test2 test3), args)
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.2
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-13 00:00:00.000000000 Z
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