optix 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +25 -0
- data/README.md +431 -0
- data/Rakefile +30 -0
- data/examples/filetool.rb +188 -0
- data/examples/printer.rb +43 -0
- data/lib/optix/trollop.rb +814 -0
- data/lib/optix/version.rb +3 -0
- data/lib/optix.rb +276 -0
- data/optix.gemspec +20 -0
- data/spec/optix_spec.rb +988 -0
- data/spec/spec_helper.rb +30 -0
- metadata +83 -0
data/examples/printer.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optix'
|
4
|
+
|
5
|
+
module Example
|
6
|
+
module Printer
|
7
|
+
# Declare the "root"-command
|
8
|
+
Optix::command do
|
9
|
+
text "I am printer. I print strings to the screen."
|
10
|
+
text "Please invoke one of my not so many sub-commands."
|
11
|
+
|
12
|
+
# Declare a global option (all subcommands inherit this)
|
13
|
+
opt :debug, "Enable debugging", :default => false
|
14
|
+
end
|
15
|
+
|
16
|
+
# Declare sub-command
|
17
|
+
Optix::command 'print' do
|
18
|
+
desc "Print a string"
|
19
|
+
text "Print a string to the screen"
|
20
|
+
params "<string>"
|
21
|
+
|
22
|
+
opt :count, "Print how many times?", :default => 1
|
23
|
+
|
24
|
+
# This block is invoked when validations pass.
|
25
|
+
exec do |cmd, opts, argv|
|
26
|
+
if argv.length < 1
|
27
|
+
raise Optix::HelpNeeded
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "DEBUGGING IS ENABLED!" if opts[:debug]
|
31
|
+
(1..opts[:count]).each do
|
32
|
+
puts argv.join(' ')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if __FILE__ == $0
|
40
|
+
# Perform the actual parsing and execution.
|
41
|
+
Optix.invoke!(ARGV)
|
42
|
+
end
|
43
|
+
|