module Dawn::CLI

Constants

DOC_SUBCOMMAND
DOC_TOP
VERSION

backward compatibility

Public Class Methods

no_operation() click to toggle source

@return [String]

# File lib/dawn/cli/parser.rb, line 153
def self.no_operation
  @@no_operation
end
no_operation=(appname) click to toggle source

@param [String] appname

# File lib/dawn/cli/parser.rb, line 160
def self.no_operation=(appname)
  @@no_operation = appname
end
not_a_command(basename, command) click to toggle source

@param [String] basename

# File lib/dawn/cli/parser.rb, line 167
def self.not_a_command(basename, command)
  # oh look, git style error message
  abort "#{basename}: '#{command}' is not a #{basename} command. See '#{basename} --help'."
end
run(argv) click to toggle source

@param [Array<String>] argv

# File lib/dawn/cli/parser.rb, line 274
def self.run(argv)
  # initial run to retrieve command
  result = Docopt.docopt(DOC_TOP, argv: argv,
                         version: Dawn::CLI::VERSION, help: false)
  command = result["<command>"]
  # run the docopt again this time with help enabled if there was no command
  unless command
    result = Docopt.docopt(DOC_TOP, argv: argv,
                           version: Dawn::CLI::VERSION, help: true)
  end

  # set the selected_app
  self.selected_app = result["--app"]
  case command
  when "create"
    Dawn::CLI::App.command(:create, result["<argv>"].first)
  when "ls"
    Dawn::CLI::App.command(:list)
  when "ps"
    Dawn::CLI::App.command(:list_gears)
  when "login"
    username = ask("Username: ")
    password = ask("Password: ") { |q| q.echo = false }
    Dawn::CLI::Auth.command(:login, username, password)
  when "logs"
    Dawn::CLI::App.command(:logs, result["<argv>"], result["--follow"])
  when "run"
    Dawn::CLI::App.command(:run, result["<argv>"])
  when "health-check"
    Dawn::CLI::Local.command(:health_check)
  when "whoami"
    Dawn::CLI::Local.command(:whoami)
  when *DOC_SUBCOMMAND.keys
    run_subcommand(command, argv)
  else
    not_a_command("dawn", command)
  end
rescue Excon::Errors::Unauthorized
  abort "dawn: unauthorized. Did you login? (dawn login)"
rescue Docopt::Exit => ex
  abort ex.message
end
run_app_command(options) click to toggle source

@param [String] command @param [Hash] options

# File lib/dawn/cli/parser.rb, line 176
def self.run_app_command(options)
  if options["delete"]
    Dawn::CLI::App.command(:delete)
  elsif options["restart"]
    Dawn::CLI::App.command(:restart)
  elsif options["scale"]
    data = options["<gear_modifier>"].each_with_object({}) do |str, hash|
      if str =~ /(\S+)([+-=])(\d+)/
        hash[$1] = [$2, $3.to_i]
      end
    end
    Dawn::CLI::App.command(:scale, data)
  else
    Dawn::CLI::App.command(:list)
  end
end
run_domain_command(options) click to toggle source
# File lib/dawn/cli/parser.rb, line 193
def self.run_domain_command(options)
  if options["add"]
    url = options["<url>"]
    Dawn::CLI::Domain.command(:add, url)
  elsif options["delete"]
    url = options["<url>"]
    Dawn::CLI::Domain.command(:delete, url)
  else
    Dawn::CLI::Domain.command(:list)
  end
end
run_drain_command(options) click to toggle source
# File lib/dawn/cli/parser.rb, line 205
def self.run_drain_command(options)
  if options["add"]
    url = options["<url>"]
    Dawn::CLI::Drain.command(:add, url)
  elsif options["delete"]
    url = options["<url>"]
    Dawn::CLI::Drain.command(:delete, url)
  else
    Dawn::CLI::Drain.command(:list)
  end
end
run_env_command(options) click to toggle source
# File lib/dawn/cli/parser.rb, line 217
def self.run_env_command(options)
  if options["get"]
    keys = options["<key_name>"]
    Dawn::CLI::Env.command(:get, *keys)
  elsif options["set"]
    data = options["<key_name=value>"].each_with_object({}) do |str, hash|
      if str =~ /(\S+)=(.*)/
        key, value = $1, $2
        hash[key] = value
      end
    end
    Dawn::CLI::Env.command(:set, data)
  elsif options["unset"]
    keys = options["<key_name>"]
    Dawn::CLI::Env.command(:unset, *keys)
  else
    Dawn::CLI::Env.command(:list)
  end
end
run_key_command(options) click to toggle source
# File lib/dawn/cli/parser.rb, line 237
def self.run_key_command(options)
  if options["add"]
    Dawn::CLI::Key.command(:add)
  elsif options["get"]
    Dawn::CLI::Key.command(:get, options["<id>"])
  elsif options["delete"]
    Dawn::CLI::Key.command(:delete, options["<id>"])
  else
    Dawn::CLI::Key.command(:list)
  end
end
run_release_command(options) click to toggle source
# File lib/dawn/cli/parser.rb, line 249
def self.run_release_command(options)
  if options["add"]
    Dawn::CLI::Release.command(:add)
  else
    Dawn::CLI::Release.command(:list)
  end
end
run_subcommand(command, argv) click to toggle source

@param [String] command @param [Array<String>] argv

# File lib/dawn/cli/parser.rb, line 261
def self.run_subcommand(command, argv)
  if argv.empty?
    subcommand = ""
  else
    result = Docopt.docopt(DOC_SUBCOMMAND[command], argv: argv,
                           version: Dawn::CLI::VERSION, help: true)
  end
  send("run_#{command}_command", result)
end
selected_app() click to toggle source

@return [String]

# File lib/dawn/cli/parser.rb, line 139
def self.selected_app
  @@selected_app
end
selected_app=(appname) click to toggle source

@param [String] appname

# File lib/dawn/cli/parser.rb, line 146
def self.selected_app=(appname)
  @@selected_app = appname
end