class Meroku::CLI

The CLI is a class responsible of handling all the command line interface logic.

Attributes

options[R]

Public Class Methods

new() click to toggle source
# File lib/meroku/cli.rb, line 10
def initialize
  @options = {}
end

Public Instance Methods

run(args = ARGV) click to toggle source
# File lib/meroku/cli.rb, line 14
def run(args = ARGV)
  @options = Options.new.parse(args)
  act_on_options
rescue Meroku::Success
  return 0
rescue StandardError => e
  print 'Error:'
  print " #{e.message}" if e.message
  print " <#{e.class}>\n"
  return 2
end

Private Instance Methods

act_on_app_options() click to toggle source
# File lib/meroku/cli.rb, line 36
def act_on_app_options
  App.create(@options[:name]) if @options[:create]
  App.list_apps if @options[:list_apps]
  App.delete_app(@options[:name]) if @options[:delete_app]
end
act_on_key_options() click to toggle source
# File lib/meroku/cli.rb, line 42
def act_on_key_options
  Key.upload if @options[:keys_add]
  Key.list if @options[:keys]
  Key.remove(@options[:key_id]) if @options[:keys_remove]
end
act_on_misc_options() click to toggle source
# File lib/meroku/cli.rb, line 48
def act_on_misc_options
  Meroku::Shared.secrets.meroku_secret = @options[:meroku_secret] \
    if @options[:meroku_secret]

  if @options[:spawn]
    Node.new
    puts 'Node created'
  end
  Meroku::Aws.terminate_all(tag: 'node') if @options[:despawn]
  Meroku::Backup.new if @options[:backup]
end
act_on_options() click to toggle source
# File lib/meroku/cli.rb, line 28
def act_on_options
  act_on_key_options
  act_on_app_options
  act_on_user_options
  act_on_misc_options
  true
end
act_on_user_options() click to toggle source
# File lib/meroku/cli.rb, line 60
def act_on_user_options
  User.login(@options[:email], @options[:password]) if @options[:login]
  User.logout if @options[:logout]
  User.signup(@options[:email], @options[:password]) if @options[:signup]
  User.unregister(@options) if @options[:unregister]
end