optitron 0.1.4 → 0.1.5
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.
- data/Gemfile.lock +1 -1
- data/README.rdoc +1 -1
- data/lib/optitron/class_dsl.rb +14 -2
- data/lib/optitron/version.rb +1 -1
- data/spec/cli_spec.rb +14 -0
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Optitron
|
2
2
|
|
3
|
-
== Sensible options parsing
|
3
|
+
== Sensible options parsing for Ruby!
|
4
4
|
|
5
5
|
Optitron strives to be simple, minimal and to do the "right thing" most of the time. The structure is easy: you have global options, a list of commands, and each of those commands takes a number of arguments and options.
|
6
6
|
|
data/lib/optitron/class_dsl.rb
CHANGED
@@ -10,13 +10,24 @@ class Optitron
|
|
10
10
|
def initialize(cls)
|
11
11
|
@cls = cls
|
12
12
|
@method_map = {}
|
13
|
+
@current_class = []
|
13
14
|
super()
|
14
15
|
end
|
15
16
|
|
17
|
+
def process_module(exp)
|
18
|
+
exp.shift
|
19
|
+
@current_class << exp.first.to_sym
|
20
|
+
process(exp)
|
21
|
+
@current_class.pop
|
22
|
+
exp.clear
|
23
|
+
exp
|
24
|
+
end
|
25
|
+
|
16
26
|
def process_class(exp)
|
17
27
|
exp.shift
|
18
|
-
@current_class
|
28
|
+
@current_class << exp.first.to_sym
|
19
29
|
process(exp)
|
30
|
+
@current_class.pop
|
20
31
|
exp.clear
|
21
32
|
exp
|
22
33
|
end
|
@@ -56,7 +67,8 @@ class Optitron
|
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
59
|
-
@
|
70
|
+
@cls
|
71
|
+
@method_map[@current_method] = arg_list if @cls.name == @current_class.map{|c| c.to_s}.join('::')
|
60
72
|
end
|
61
73
|
end
|
62
74
|
|
data/lib/optitron/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module AModule
|
4
|
+
class CLIInAModule < Optitron::CLI
|
5
|
+
desc "a method"
|
6
|
+
def method(arg1)
|
7
|
+
puts "calling with #{arg1}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
class CLIExample < Optitron::CLI
|
4
13
|
|
5
14
|
def a_method_we_didnt_describe
|
@@ -101,4 +110,9 @@ describe "Optitron::Parser defaults" do
|
|
101
110
|
it "should get type hinting from arg names" do
|
102
111
|
capture(:stdout) { CLIExampleWithArgHinting.dispatch(%w(use_too asd 123)) }.should == "using this too \"asd\" 123\n"
|
103
112
|
end
|
113
|
+
|
114
|
+
it "should dispatch from within a module" do
|
115
|
+
AModule::CLIInAModule.build
|
116
|
+
AModule::CLIInAModule.optitron_parser.help.should == "Commands\n\nmethod [arg1] # a method\n\nGlobal options\n\n-?/--help # Print help message"
|
117
|
+
end
|
104
118
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optitron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Hull
|