optix 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
+