optitron 0.1.0 → 0.1.1

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.0.11)
4
+ optitron (0.1.0)
5
5
  callsite (= 0.0.4)
6
6
  ruby2ruby (= 1.2.4)
7
7
  ruby_parser (>= 2.0)
@@ -2,11 +2,11 @@
2
2
 
3
3
  == Sensible options parsing
4
4
 
5
- Optitron strives to be simple, minimal and to do the "right thing" most of the time. The structure is simple, you have global options, a list of commands, and each of those commands takes a number of arguments and options.
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
 
7
7
  == Usage
8
8
 
9
- To create an Optitron CLI, start with a class you want to wire up as a CLI. In our example, we'll use the class Runner, which we want to work as a CLI.
9
+ To create an Optitron command line interface (CLI), start with a class you want to wire up as a CLI. In our example, we'll use the class Runner, which we want to work as a CLI.
10
10
 
11
11
  class Runner
12
12
  def start
@@ -41,7 +41,48 @@ To make this class suitable for use as a CLI, either extend <tt>Optitron::CLI</t
41
41
  end
42
42
  end
43
43
 
44
- Only methods described will be available to the CLI. If you have a method that needs arguments, simply include them as method arguments. It will respect splats and defaults. Options are specified with the +opt+ method in your class, as follows:
44
+ === Help command
45
+
46
+ Help is added by default, but, if you don't want to use this, include the command +dont_use_help+ in your class. Help is available from either <tt>--help</tt> or <tt>-?</tt>.
47
+
48
+ === Arguments
49
+
50
+ Only methods described will be available to the CLI. If you have a method that needs arguments, simply include them as method arguments. It will respect splats and defaults. For instance
51
+
52
+ desc "Starts the process"
53
+ def start(mode)
54
+ # ... starts
55
+ end
56
+
57
+ Will generate
58
+
59
+ start [mode] # Starts the process
60
+
61
+ In your help file.
62
+
63
+ desc "Starts the process"
64
+ def start(mode = 'production')
65
+ # ... starts
66
+ end
67
+
68
+ Will generate
69
+
70
+ start <mode="production"> # Starts the process
71
+
72
+ And
73
+
74
+ desc "Starts the process"
75
+ def start(*modes)
76
+ # ... starts
77
+ end
78
+
79
+ Will generate
80
+
81
+ start <modes1 modes2 ...> # Starts the process
82
+
83
+ === Options
84
+
85
+ Options are specified with the +opt+ method in your class, as follows:
45
86
 
46
87
  class Runner < Optitron::CLI
47
88
  desc "Starts the process"
@@ -70,10 +111,6 @@ The last line in your runner has to be the class name and dispatch. This will pa
70
111
  # ... your methods
71
112
  end
72
113
  Runner.dispatch
73
-
74
- As well, help is added by default, but, if you don't want to use this, include the command +dont_use_help+ in your class.
75
-
76
- == How to configure options
77
114
 
78
115
  Options can have defaults, types and inclusion checks. Here are all the options available on an opt:
79
116
 
@@ -0,0 +1,15 @@
1
+ require 'optitron'
2
+
3
+ class Runner < Optitron::CLI
4
+ class_opt 'verbose'
5
+ class_opt 'environment', :in => %w(production stage development test), :default => 'development'
6
+ class_opt 'volume', :in => 1..10
7
+
8
+ desc "Install stuff"
9
+ opt 'force'
10
+ def install(file, source = ".")
11
+ puts "Installing #{file} from #{source.inspect} with params: #{params.inspect}"
12
+ end
13
+ end
14
+
15
+ Runner.dispatch
@@ -126,7 +126,7 @@ class Optitron
126
126
 
127
127
  def build
128
128
  unless @built
129
- optitron_dsl.root.help# if send(:class_variable_defined?, :@@suppress_help)
129
+ optitron_dsl.root.help unless send(:class_variable_defined?, :@@suppress_help)
130
130
  @cmds.each do |(cmd_name, cmd_desc, opts)|
131
131
  args = method_args[cmd_name.to_sym]
132
132
  arity = instance_method(cmd_name).arity
@@ -1,3 +1,3 @@
1
1
  class Optitron
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -133,4 +133,20 @@ describe "Optitron::Parser options" do
133
133
  end
134
134
  end
135
135
 
136
+ context "array options with a comment" do
137
+ before(:each) do
138
+ @parser = Optitron.new {
139
+ cmd "install" do
140
+ opt "things", :type => :array
141
+ end
142
+ }
143
+ end
144
+
145
+ it "should parse '--things=one two three install'" do
146
+ response = @parser.parse(%w(--things=one two three install))
147
+ response.valid?.should be_true
148
+ response.params.should == {'things' => ['one', 'two', 'three']}
149
+ end
150
+ end
151
+
136
152
  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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
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-20 00:00:00 -07:00
18
+ date: 2010-08-21 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -142,6 +142,7 @@ files:
142
142
  - Gemfile.lock
143
143
  - README.rdoc
144
144
  - Rakefile
145
+ - examples/cli.rb
145
146
  - lib/optitron.rb
146
147
  - lib/optitron/class_dsl.rb
147
148
  - lib/optitron/cli.rb