class GitContext::CLI

Constants

COMMAND_CLASSES

Public Class Methods

new(configuration) click to toggle source
# File lib/git_context/cli.rb, line 14
def initialize(configuration)
  @configuration = configuration
  @interaction = Interaction.new
end

Public Instance Methods

exec(command_name) click to toggle source
# 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

Private Instance Methods

command_for(command) click to toggle source
# File lib/git_context/cli.rb, line 32
def command_for(command)
  klass = COMMAND_CLASSES.fetch(command.to_sym)
  Commands.const_get(klass)
end