Class: Fum::Application

Inherits:
Object
  • Object
show all
Includes:
CommandManager
Defined in:
lib/fum/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CommandManager

#commands, included, #initialize, #parse_command_options, #run_command

Instance Attribute Details

#main_declObject

Returns the value of attribute main_decl.



18
19
20
# File 'lib/fum/application.rb', line 18

def main_decl
  @main_decl
end

Instance Method Details

#load_credentialsObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fum/application.rb', line 99

def load_credentials
  require 'yaml'

  config_file = File.expand_path('~/.fum')

  options = YAML.load(File.read(config_file))

  # Convert to symbols
  options.each { |key, value|
    options.delete(key)
    options[key.to_sym] = value
  }
  options
end

#load_file(filename) ⇒ Object



95
96
97
# File 'lib/fum/application.rb', line 95

def load_file(filename)
  Fum::Lang::FumFile.load(filename)
end

#process_command_lineObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fum/application.rb', line 52

def process_command_line
  #global_options = Trollop::options do

  sub_commands = commands.keys.map { |c| c.to_s }

  parser = Trollop::Parser.new do
    version "fum #{VERSION}"
    banner "usage: fum <filename> [options] <command> [command-options]\n\nCommands are (use --help after command to see additional usage):\n  launch\n  list\n\nwhere [options] are:\n    EOS\n\n    opt :credentials, \"File containing AWS credentials to use\", :type => :string\n    opt :noop, \"Do nothing, print steps to be executed.\", :default => false\n    opt :verbose, \"Print verbose output.\", :default => false\n    stop_on sub_commands #commands.keys.map { |c| c.to_s }\n  end\n\n  global_options = Trollop::with_standard_exception_handling parser do\n    o = parser.parse ARGV\n    raise Trollop::HelpNeeded if ARGV.empty?\n    @filename = ARGV.shift\n    raise Trollop::HelpNeeded if ARGV.empty?\n    @command_name = ARGV.shift\n    o\n  end\n\n  config = load_credentials\n\n  Fog.credentials = {\n      :aws_access_key_id => config[:access_key_id],\n      :aws_secret_access_key => config[:secret_access_key]\n  }\n\n  global_options\nend\n"

#startObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fum/application.rb', line 29

def start
  global_options = process_command_line

  @beanstalk = Fog::AWS[:beanstalk]

  command = commands[@command_name.to_sym]

  if global_options[:verbose]
    puts "Loading definition file #{@filename}"
  end

  @main_decl = load_file(@filename)

  if command
    options = parse_command_options(@command_name.to_sym)
    options.merge!(global_options)
    run_command(@command_name.to_sym, options)
  else
    parser.die "Unknown command '#{@command_name}'", nil
  end

end