Class: GitContext::CLI

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

Constant Summary collapse

COMMAND_CLASSES =
{
  help: 'Help',
  setup: 'Setup',
  create_profile: 'CreateProfile',
  create_context: 'CreateContext',
  delete_profile: 'DeleteProfile',
  list_profile: 'ListProfile'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ CLI

Returns a new instance of CLI.



14
15
16
17
# File 'lib/git_context/cli.rb', line 14

def initialize(configuration)
  @configuration = configuration
  @interaction = Interaction.new
end

Instance Method Details

#exec(command_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/git_context/cli.rb', line 19

def exec(command_name)
  command_name ||= 'help'
  command_class = command_for(command_name)
  command = command_class.new(interaction: @interaction, configuration: @configuration)
  command.call
rescue KeyError
  warn "Unknown command #{command_name}. Supported commands are #{COMMAND_CLASSES.keys.map(&:to_s)}"
rescue TTY::Reader::InputInterrupt
  warn "\nInterrupted"
end