lab42_options 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +10 -0
- data/README.md +23 -0
- data/lib/lab42/options.rb +16 -0
- data/lib/lab42/options/forwarder.rb +10 -0
- data/lib/lab42/options/parser.rb +30 -0
- data/lib/lab42/options/version.rb +5 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89f7aaf93a227feba15aea3a108e7d03dcde0042
|
4
|
+
data.tar.gz: 6237261e7e8ffe64140ad442540eb98010bd070a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99e69a7290052a99a017596ef79681c7d3d02d63ddfb7b6a92503906238579338384e5f8a31c72c54727d016bb7a65361cea22acb60d085dedbd1e3bbcca7be2
|
7
|
+
data.tar.gz: c45b3d89c9b9221d40251b2694c3799c7b38f6fb2d09ae239f3ae9f937d9a5ae989728bb6775a99baf7f84a271d10c35bcb157f07f78f083b934a88b2f9be333
|
data/LICENSE
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2012 Robert Dober
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
6
|
+
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
8
|
+
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
|
+
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Lab42, Programmers' Best Friend In Ruby 2
|
2
|
+
|
3
|
+
## Options
|
4
|
+
|
5
|
+
Lets us specify command line options with the same syntax as ruby parameters
|
6
|
+
|
7
|
+
```
|
8
|
+
my_shiny_gem "hello", "world", :verbose, answer: 42
|
9
|
+
```
|
10
|
+
|
11
|
+
Will yield
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'lab42/options'
|
15
|
+
|
16
|
+
options = Lab42::Options.new.parse ARGV
|
17
|
+
options.args # --> %W{ hello world }
|
18
|
+
options.first # --> "hello"
|
19
|
+
options[:verbose] # --> true
|
20
|
+
options.verbose # --> true
|
21
|
+
options[:answer] # --> "42"
|
22
|
+
options.answer # --> "42"
|
23
|
+
```
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require_relative './options/parser'
|
3
|
+
require_relative './options/forwarder'
|
4
|
+
|
5
|
+
module Lab42
|
6
|
+
class Options
|
7
|
+
def parse *args
|
8
|
+
args = args.first if Array === args.first
|
9
|
+
result = OpenStruct.new Lab42::Options::Parser.new.parse( args )
|
10
|
+
result.forwarding_to :kwds
|
11
|
+
end
|
12
|
+
private
|
13
|
+
def intialize *args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Lab42
|
2
|
+
class Options
|
3
|
+
class Parser
|
4
|
+
attr_accessor :data, :kwds, :positionals
|
5
|
+
def parse args
|
6
|
+
self.data = {to_a: args}
|
7
|
+
self.kwds = {}
|
8
|
+
self.positionals = []
|
9
|
+
parse_all args
|
10
|
+
data.merge kwds: OpenStruct.new(kwds), args: positionals
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def parse_all args
|
15
|
+
e = (args[0..-1] || []).enum_for :each
|
16
|
+
loop do
|
17
|
+
case current = e.next
|
18
|
+
when /\A:(.*)/
|
19
|
+
kwds.update $1.to_sym => true
|
20
|
+
when /\A(.*):\z/
|
21
|
+
kwds.update $1.to_sym => e.next
|
22
|
+
else
|
23
|
+
positionals << current
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lab42_options
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Dober
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.12
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.12
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
description: Specify command line arguments with Ruby Syntax
|
42
|
+
email: robert.dober@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/lab42/options.rb
|
48
|
+
- lib/lab42/options/parser.rb
|
49
|
+
- lib/lab42/options/forwarder.rb
|
50
|
+
- lib/lab42/options/version.rb
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
homepage: https://github.com/RobertDober/lab42_options
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.0.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.0.3
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Command Lines the Ruby Way
|
77
|
+
test_files: []
|