optitron 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- optitron (0.1.2)
4
+ optitron (0.1.3)
5
5
  callsite (= 0.0.4)
6
6
  ruby2ruby (= 1.2.4)
7
7
  ruby_parser (>= 2.0)
@@ -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 &&= possible_arg_type.to_sym
143
- arg_opts = { :default => arg_default && eval(arg_default), :type => arg_types && arg_types.shift || possible_arg_type }
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
@@ -35,6 +35,9 @@ class Optitron
35
35
  if arg.default
36
36
  arg_line << "=#{arg.default.inspect}"
37
37
  end
38
+ if arg.type and !arg.greedy? and !arg.string?
39
+ arg_line << "(#{arg.type.to_s.upcase})"
40
+ end
38
41
  arg_line << (arg.required? ? ']' : '>')
39
42
  arg_line
40
43
  end
@@ -1,3 +1,3 @@
1
1
  class Optitron
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -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 # Use this\n -u/--use_opt \nuse_too [one] <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"
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
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-23 00:00:00 -07:00
18
+ date: 2010-08-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency