minimist 0.3.0 → 0.4.0

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: cf3aae651ba5bbb43adc67d69864814b4c67beaf
4
- data.tar.gz: 83f42f940f7494e05fc56e5aa6c28c5cc4371246
3
+ metadata.gz: e7fb0a6d33c9ccc2e3cd68322628d29bc645d22c
4
+ data.tar.gz: 62cb29826e6e208ad0a1269d31cb914f37a675cd
5
5
  SHA512:
6
- metadata.gz: b83242e0bb2609de9afc5e886f25eb2c4dd65f7afd79bd82eb69dee3806666ffdb518c860b5c1e8cb0bd732f538acc8869fe0d3cd2173f5a03b5de57c3bf78ed
7
- data.tar.gz: ba7455ad470b90d6c3a5fa3a9cd99cad73e67b15e6a5f5a10a5c1d3981b47ca1c8e7a0d3182546046f99448e54db774061cd599396c645cdb7b06acab6af2a4b
6
+ metadata.gz: 8eb9b785e24a770b3c1a98f217b8e09a454e4d77ac024269a876584934842eb489656649e038a111e83861c847468f975957b9b507143e9c35929bb2e5dab02e
7
+ data.tar.gz: e404dd665e0d43c0abfa6eca42665354e2ffce7ac0dfd0b28f5a3af75aac908db8c84884bb36a91070c80a7f8dcce96ecaa93cce701743bee2492d288194a1d8
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Minimist
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/minimist`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
26
-
27
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
27
+ It accepts a string array and returns a hash containing commands and options.
30
28
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- # match --skip=true arg types
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
- argv_object[:options][match_data[1].to_sym] = true
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, false]
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]
@@ -1,3 +1,3 @@
1
1
  module Minimist
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.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-06 00:00:00.000000000 Z
11
+ date: 2015-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler