Class: Toga::CLI
Overview
The main root class of Toga
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#options ⇒ Object
Returns the value of attribute options.
-
#return_value ⇒ Object
Returns the value of attribute return_value.
Instance Method Summary collapse
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #usage! ⇒ Object
Methods included from Error
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/toga/cli.rb', line 12 def initialize(*args) @args = args @return_value = 0 return usage! if args.length == 0 cmd = @args.shift begin @command = Commands.const_get(cmd.capitalize) rescue if !@command fail "Invalid command '#{cmd}'.", "Type `toga` or `toga help` for usage" return end end result = @command.run!(@args) if result.is_a? String $stdout.puts result end result end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/toga/cli.rb', line 8 def args @args end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/toga/cli.rb', line 9 def @options end |
#return_value ⇒ Object
Returns the value of attribute return_value.
10 11 12 |
# File 'lib/toga/cli.rb', line 10 def return_value @return_value end |
Instance Method Details
#usage! ⇒ Object
37 38 39 40 |
# File 'lib/toga/cli.rb', line 37 def usage! path = File.(File.dirname(__FILE__) + '/../../USAGE') $stdout.puts File.open(path).read end |