lab419_options 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3e134811569e14510a2c783ebb86be444f47b918
4
+ data.tar.gz: a3faaa8942e605a642f8f33cd2c97dfeb4a408ed
5
+ SHA512:
6
+ metadata.gz: a37ab36beae3085106e40b5ca4d562820e06bc8e38fcea106b12a0f1603b99ff384d43d812506dc031cd15b3bb9471d5faa5042158d215864d88dd1bd7fa769d
7
+ data.tar.gz: 1a2b2e3f2e8793992df357222bbdfea126593b19582af2d41cf5b9e3bb46d74d9e667df3aa687e0cd62df97309a53d1c66d6a39d97efe0ffbe62ec6e5484adbc
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
+ # Lab419, Programmers' Best Friend
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 'lab419/options'
15
+
16
+ options = Lab419::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 Lab419
6
+ class Options
7
+ def parse *args
8
+ args = args.first if Array === args.first
9
+ result = OpenStruct.new Lab419::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,10 @@
1
+ require 'ostruct'
2
+ class OpenStruct
3
+ def forwarding_to key
4
+ h = to_h
5
+ k = self[key].to_h
6
+ # require 'pry'
7
+ # binding.pry
8
+ self.class.new k.merge( h )
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ module Lab419
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
@@ -0,0 +1,5 @@
1
+ module Lab419
2
+ class Options
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lab419_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/lab419/options/forwarder.rb
48
+ - lib/lab419/options/parser.rb
49
+ - lib/lab419/options/version.rb
50
+ - lib/lab419/options.rb
51
+ - LICENSE
52
+ - README.md
53
+ homepage: https://github.com/RobertDober/lab419/tree/options-0.1.0/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: []