optitron 0.1.3 → 0.1.4
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/lib/optitron/class_dsl.rb +7 -3
- data/lib/optitron/help.rb +3 -0
- data/lib/optitron/version.rb +1 -1
- data/spec/cli_spec.rb +6 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
data/lib/optitron/class_dsl.rb
CHANGED
@@ -130,6 +130,7 @@ class Optitron
|
|
130
130
|
|
131
131
|
def build
|
132
132
|
unless @built
|
133
|
+
target = optitron_parser.target
|
133
134
|
optitron_dsl.root.help unless send(:class_variable_defined?, :@@suppress_help)
|
134
135
|
@cmds.each do |(cmd_name, cmd_desc, opts)|
|
135
136
|
args = method_args[cmd_name.to_sym]
|
@@ -139,8 +140,11 @@ class Optitron
|
|
139
140
|
opts.each { |o| opt *o }
|
140
141
|
args.each do |(arg_name, arg_type, arg_default)|
|
141
142
|
possible_arg_type = arg_name.to_s[/_(string|hash|array|numeric|int|float)$/, 1]
|
142
|
-
possible_arg_type
|
143
|
-
|
143
|
+
if possible_arg_type && (arg_types.nil? || !arg_types.first)
|
144
|
+
possible_arg_type = possible_arg_type.to_sym
|
145
|
+
arg_name = arg_name.to_s[/^(.*)_(?:string|hash|array|numeric|int|float)$/, 1]
|
146
|
+
end
|
147
|
+
arg_opts = { :default => arg_default && target.instance_eval(arg_default), :type => arg_types && arg_types.shift || possible_arg_type }
|
144
148
|
case arg_type
|
145
149
|
when :required
|
146
150
|
arg arg_name.to_s, arg_opts
|
@@ -158,8 +162,8 @@ class Optitron
|
|
158
162
|
end
|
159
163
|
|
160
164
|
def dispatch(args = ARGV, &blk)
|
161
|
-
build
|
162
165
|
optitron_parser.target = blk ? blk.call : new
|
166
|
+
build
|
163
167
|
response = optitron_parser.parse(args)
|
164
168
|
if response.valid?
|
165
169
|
optitron_parser.target.params = response.params
|
data/lib/optitron/help.rb
CHANGED
data/lib/optitron/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -69,7 +69,7 @@ end
|
|
69
69
|
describe "Optitron::Parser defaults" do
|
70
70
|
it "should generate the correct help" do
|
71
71
|
CLIExample.build
|
72
|
-
CLIExample.optitron_parser.help.strip.should == "Commands\n\nuse
|
72
|
+
CLIExample.optitron_parser.help.strip.should == "Commands\n\nuse # Use this\n -u/--use_opt \nuse_too [one(HASH)] <two=\"three\"> # Use this too\n -a/--another_opt \nuse_greedy [one] <two1 two2 ...> # Use this three\n -A/--another_opt_as_well=[NUMERIC] \nwith_array <ary=[1, 2, 3]> # something with an array\n\nGlobal options\n\n-v/--verbose \n-?/--help # Print help message"
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should dispatch" do
|
@@ -93,6 +93,11 @@ describe "Optitron::Parser defaults" do
|
|
93
93
|
capture(:stdout) { NoHelpExample.dispatch(%w(--help)) }.should == "Unknown command\nHelp is unrecognized\n"
|
94
94
|
end
|
95
95
|
|
96
|
+
it "should strip the type information from the names when its using the _type info" do
|
97
|
+
CLIExampleWithArgHinting.build
|
98
|
+
CLIExampleWithArgHinting.optitron_parser.help.strip.should == "Commands\n\nuse_too [one] [two(NUMERIC)] # Use this too\n\nGlobal options\n\n-?/--help # Print help message"
|
99
|
+
end
|
100
|
+
|
96
101
|
it "should get type hinting from arg names" do
|
97
102
|
capture(:stdout) { CLIExampleWithArgHinting.dispatch(%w(use_too asd 123)) }.should == "using this too \"asd\" 123\n"
|
98
103
|
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: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Hull
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-24 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|