lucy-goosey 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,7 +5,7 @@ Command line parsing sucks.
5
5
 
6
6
  It assumes some unix conventions, and doesn't mess with your environment or do anything magic.
7
7
 
8
- I write the tests first and use whatever implementation makes them pass.
8
+ Heavily tested.
9
9
 
10
10
 
11
11
  ## Installation
@@ -4,11 +4,20 @@ module Lucy
4
4
  module Goosey
5
5
  UNIX_SINGLE_FLAG = /^-/
6
6
  UNIX_DOUBLE_FLAG = /^--/
7
+ EQUAL = /=/
8
+
9
+
10
+ def self.leading_word?(word)
11
+ ! (word.match(UNIX_DOUBLE_FLAG) || word.match(UNIX_SINGLE_FLAG) || word.match(EQUAL))
12
+ end
13
+
7
14
 
8
15
  def self.parse_options(_args)
9
16
  args = _args.dup
10
17
  config = {}
11
18
 
19
+ args = args[1..-1] while leading_word?(args.first)
20
+
12
21
  args.size.times do
13
22
  break if args.empty?
14
23
  arg = args.shift
@@ -1,5 +1,5 @@
1
1
  module Lucy
2
2
  module Goosey
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -100,6 +100,11 @@ describe Lucy::Goosey do
100
100
  end
101
101
 
102
102
  describe "edge cases" do
103
+ it "ignores leading words" do
104
+ result = Lucy::Goosey.parse_options(%w(wtf bbq --bar foo=baz --baz=bar -n 1 --bap))
105
+ result.must_equal({ 'foo' => 'baz', 'baz' => 'bar', 'bar' => true, 'n' => '1', 'bap' => true })
106
+ end
107
+
103
108
  it "works in any order" do
104
109
  result = Lucy::Goosey.parse_options(%w(--bar foo=baz --baz=bar bob=true --bap))
105
110
  result.must_equal({ 'foo' => 'baz', 'baz' => 'bar', 'bar' => true, 'bob' => true, 'bap' => true })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucy-goosey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -74,7 +74,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  segments:
76
76
  - 0
77
- hash: 1570045652843307468
77
+ hash: -3205257808649039205
78
78
  required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  none: false
80
80
  requirements:
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  version: '0'
84
84
  segments:
85
85
  - 0
86
- hash: 1570045652843307468
86
+ hash: -3205257808649039205
87
87
  requirements: []
88
88
  rubyforge_project:
89
89
  rubygems_version: 1.8.23