Class: Kobold::CLI

Inherits:
Object
  • Object
show all
Includes:
AdminCommands, CheckoutCommands, ErrorHandling, FlagParser, InitCommands, LifecycleCommands, ListCommands, Output, RepoCommands, UpdateCommands
Defined in:
lib/Kobold/cli.rb,
lib/Kobold/cli/output.rb,
lib/Kobold/cli/flag_parser.rb,
lib/Kobold/cli/init_commands.rb,
lib/Kobold/cli/list_commands.rb,
lib/Kobold/cli/repo_commands.rb,
lib/Kobold/cli/admin_commands.rb,
lib/Kobold/cli/error_handling.rb,
lib/Kobold/cli/update_commands.rb,
lib/Kobold/cli/checkout_commands.rb,
lib/Kobold/cli/lifecycle_commands.rb

Overview

CLI entry point — every subcommand is a thin wrapper around Kobold::Manager.

Defined Under Namespace

Modules: AdminCommands, CheckoutCommands, ErrorHandling, FlagParser, InitCommands, LifecycleCommands, ListCommands, Output, RepoCommands, UpdateCommands

Constant Summary collapse

COMMAND_MAP =
{
  "init" => :cmd_init, "invoke" => :cmd_invoke,
  "fetch" => :cmd_fetch, "register" => :cmd_register,
  "unregister" => :cmd_unregister, "checkout" => :cmd_checkout,
  "branch" => :cmd_branch, "list" => :cmd_list,
  "clean" => :cmd_clean, "add" => :cmd_add,
  "remove" => :cmd_remove, "update" => :cmd_update,
  "db" => :cmd_db, "config" => :cmd_config,
  "version" => :cmd_version, "v" => :cmd_version
}.freeze
EXIT_SUCCESS =
0
EXIT_ERROR =
1
EXIT_USAGE =
2

Constants included from ErrorHandling

ErrorHandling::ERROR_HANDLERS

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = ARGV) ⇒ CLI

Returns a new instance of CLI.



43
44
45
46
47
48
# File 'lib/Kobold/cli.rb', line 43

def initialize(argv = ARGV)
  @argv = argv.dup
  @database = "default"
  @command = nil
  @args = []
end

Class Method Details

.report_error(msg) ⇒ Object



36
37
38
# File 'lib/Kobold/cli/error_handling.rb', line 36

def self.report_error(msg)
  $stderr.puts "\e[31m\u2717\e[0m #{msg}" # rubocop:disable Style/StderrPuts
end

.report_format_error(err) ⇒ Object



40
41
42
43
# File 'lib/Kobold/cli/error_handling.rb', line 40

def self.report_format_error(err)
  report_error("Format error: #{err.message}")
  $stderr.puts "  \e[90mYour .kobold file may need format version #{FORMAT_VERSION}.\e[0m" # rubocop:disable Style/StderrPuts
end

.report_with_hint(msg, hint_msg) ⇒ Object



45
46
47
48
# File 'lib/Kobold/cli/error_handling.rb', line 45

def self.report_with_hint(msg, hint_msg)
  report_error(msg)
  $stderr.puts "  \e[90m#{hint_msg}\e[0m" # rubocop:disable Style/StderrPuts
end

Instance Method Details

#runObject



50
51
52
53
54
55
# File 'lib/Kobold/cli.rb', line 50

def run
  parse_global_flags
  dispatch
rescue StandardError => e
  handle_error(e)
end