Class: Toga::CLI

Inherits:
Object
  • Object
show all
Includes:
Error
Defined in:
lib/toga/cli.rb

Overview

The main root class of Toga

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Error

included

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

#argsObject

Returns the value of attribute args.



8
9
10
# File 'lib/toga/cli.rb', line 8

def args
  @args
end

#optionsObject

Returns the value of attribute options.



9
10
11
# File 'lib/toga/cli.rb', line 9

def options
  @options
end

#return_valueObject

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.expand_path(File.dirname(__FILE__) + '/../../USAGE')
  $stdout.puts File.open(path).read
end