Class: Magellan::Cli::Command
- Includes:
- FileAccess
- Defined in:
- lib/magellan/cli/command.rb
Constant Summary collapse
- COMMAND_ORDER =
%w[login] + Resources::MAPPING.values + %w[cloudsql_instance] + Messaging::MAPPING.values
Constants included from FileAccess
FileAccess::DEFAULT_SELECTION_FILENAME
Class Method Summary collapse
-
.help(shell, subcommand = false) ⇒ Object
overwrite Magellan::Cli::Base.help method.
-
.start(given_args = ARGV, config = {}) ⇒ Object
override Thor::Base.start method.
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, log_warning, 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.}", verbose) end begin super(given_args, config) rescue Magellan::Cli::Error => e log_error(e.) block_given? ? yield(e) : exit(1) rescue => e log_error("[#{e.class}] #{e.}") log_verbose(" " << e.backtrace.join("\n "), verbose) block_given? ? yield(e) : exit(1) end end |
Instance Method Details
#info ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# 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 ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/magellan/cli/command.rb', line 76 def login unless email = [:email] print "email: " email = STDIN.gets.strip end password = [:password] token = [: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 |