class Magellan::Cli::Command

Constants

COMMAND_ORDER

Public Class Methods

help(shell, subcommand = false) click to toggle source

overwrite Magellan::Cli::Base.help method

Calls superclass method Magellan::Cli::Base::help
# File lib/magellan/cli/command.rb, line 43
def help(shell, subcommand = false)
  super(shell, subcommand)

  shell.say
  shell.say "RESOURCES:"
  shell.say "  " << Resources::MAPPING.keys.join(", ")
  shell.say "  " << I18n.t(:for_more_detail, scope: [:command, :cmd_help], command: File.basename($0))
  shell.say
end
start(given_args = ARGV, config = {}) { |e| ... } click to toggle source

override Thor::Base.start method

Calls superclass method
# File lib/magellan/cli/command.rb, line 13
def start(given_args = ARGV, config = {})
  Magellan::Cli::FileAccess.ensure_config_dir
  verbose = ARGV.include?("-V") || ARGV.include?("--verbose")
  # class_options verbose and version are defined in Magellan::Cli::Base
  if (ARGV == ["-v"] || ARGV == ["--version"])
    log_info(File.basename($0) << " " << Magellan::Cli::VERSION)
    exit(0)
  elsif ARGV.include?("-v") || ARGV.include?("--version")
    log_info(File.basename($0) << " " << Magellan::Cli::VERSION)
  end
  begin
    GemUpdate.search do |name, v|
      log_info("\n\e[32mNew version available. try `gem install #{name} -v #{v}`\e[0m\n")
    end
  rescue => e
    log_verbose("[#{e.class}] #{e.message}", verbose)
  end
  begin
    super(given_args, config)
  rescue Magellan::Cli::Error => e
    log_error(e.message)
    block_given? ? yield(e) : exit(1)
  rescue => e
    log_error("[#{e.class}] #{e.message}")
    log_verbose("  " << e.backtrace.join("\n  "), verbose)
    block_given? ? yield(e) : exit(1)
  end
end

Public Instance Methods

info() click to toggle source
# File lib/magellan/cli/command.rb, line 110
def info
  http_conn.check_login_auth!
  selections = load_selections || {}
  d = {"user" => http_conn.login_auth["email"] }
  Resources::MAPPING.each do |classname, name|
    klass = ::Magellan::Cli::Resources.const_get(classname)
    attr = klass.caption_attr
    if val = selections[ klass.parameter_name ]
      d[name] = val[attr] ? val[attr] : val.inspect
    end
  end
  log_info YAML.dump(d)
end
login() click to toggle source
# File lib/magellan/cli/command.rb, line 76
def login
  unless email = options[:email]
    print "email: "
    email = STDIN.gets.strip
  end

  password = options[:password]
  token    = options[:authentication_token]

  if password.blank? && token.blank?
    log_warning I18n.t(:warning, scope: :login)
    print "password: "
    password = STDIN.noecho(&:gets).chomp
    puts ""
  end

  if password.blank? && token.blank?
    print "authentication_token: "
    token = STDIN.noecho(&:gets).chomp
    puts ""
  end

  result =
    if password.present?
      login!(email, password)
    else
      login_by_token!(email, token)
    end

  select_single_resources
  result
end
select_single_resources() click to toggle source
# File lib/magellan/cli/command.rb, line 126
def select_single_resources
  %w[Organization Project ClientVersion Stage Worker Image Cloudsql].each do |class_name|
    klass = Magellan::Cli::Resources.const_get(class_name)
    cmd = klass.new
    res = cmd.send(:query_list)
    if res.length == 1
      value = res.first[klass.caption_attr]
      cmd.select(value)
    else
      break
    end
  end
end