Class: Magellan::Cli::Command

Inherits:
Base
  • Object
show all
Includes:
FileAccess
Defined in:
lib/magellan/cli/command.rb

Constant Summary collapse

COMMAND_ORDER =
%w[login] + Resources::MAPPING.values + Messaging::MAPPING.values

Constants included from FileAccess

FileAccess::DEFAULT_SELECTION_FILENAME

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FileAccess

ensure_config_dir, load_selection, load_selections, remove_selection_file, selection_filename, update_selections

Methods inherited from Base

command_help, log_error, log_info, log_success, log_verbose, puts_with_color, sorted_commands, sorted_printable_commands, update_common_help_message

Class Method Details

.help(shell, subcommand = false) ⇒ Object

overwrite Magellan::Cli::Base.help method



43
44
45
46
47
48
49
50
51
# 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 = {}) ⇒ Object

override Thor::Base.start method



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

Instance Method Details

#info ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/magellan/cli/command.rb', line 88

def info
  cli = Magellan::Cli::.new
  cli.
  selections = load_selections || {}
  d = {"user" => cli.["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 ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/magellan/cli/command.rb', line 72

def 
  unless email = options[:email]
    print "email: "
    email = STDIN.gets.strip
  end

  unless password = options[:password]
    print "password: "
    password = STDIN.noecho(&:gets).chomp
    puts ""
  end

  Magellan::Cli::Http.new.login!(email, password)
end