optitron 0.1.4 → 0.1.5

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.3)
4
+ optitron (0.1.4)
5
5
  callsite (= 0.0.4)
6
6
  ruby2ruby (= 1.2.4)
7
7
  ruby_parser (>= 2.0)
@@ -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
 
@@ -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 = exp.first.to_sym
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
- @method_map[@current_method] = arg_list if @cls.name.to_sym == @current_class
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
 
@@ -1,3 +1,3 @@
1
1
  class Optitron
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -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: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull