Class: Slk::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/cli.rb

Overview

Command-line interface entry point that dispatches to commands rubocop:disable Metrics/ClassLength

Constant Summary collapse

COMMANDS =
{
  'status' => Commands::Status,
  'presence' => Commands::Presence,
  'dnd' => Commands::Dnd,
  'messages' => Commands::Messages,
  'thread' => Commands::Thread,
  'unread' => Commands::Unread,
  'catchup' => Commands::Catchup,
  'activity' => Commands::Activity,
  'later' => Commands::Later,
  'search' => Commands::Search,
  'preset' => Commands::Preset,
  'workspaces' => Commands::Workspaces,
  'cache' => Commands::Cache,
  'emoji' => Commands::Emoji,
  'config' => Commands::Config,
  'help' => Commands::Help
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv, output: nil) ⇒ CLI

Returns a new instance of CLI.



26
27
28
29
30
# File 'lib/slk/cli.rb', line 26

def initialize(argv, output: nil)
  @argv = argv.dup
  @output = output || Formatters::Output.new
  @output_injected = !output.nil?
end

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/slk/cli.rb', line 32

def run
  command_name, *args = @argv

  return show_help if help_requested?(command_name)
  return show_version if version_requested?(command_name)

  dispatch_command(command_name, args)
rescue Interrupt
  handle_interrupt
rescue StandardError => e
  handle_error(e)
end