class HammerCLI::ShellCommand

Constants

DEFAULT_HISTORY_FILE

Public Instance Methods

execute() click to toggle source
# File lib/hammer_cli/shell.rb, line 82
def execute
  ShellMainCommand.load_commands(HammerCLI::MainCommand)

  Readline.completion_append_character = ''
  Readline.completer_word_break_characters = ' ='
  Readline.completion_proc = complete_proc

  stty_save = `stty -g`.chomp if $stdin.tty?

  history = ShellHistory.new(Settings.get(:ui, :history_file) || DEFAULT_HISTORY_FILE)

  begin
    print_welcome_message
    while line = Readline.readline(prompt)

      history.push(line)

      line = HammerCLI::CompleterLine.new(line)
      ShellMainCommand.run('hammer', line, context) unless line.empty?
    end
  rescue Interrupt; end

  puts
  # Restore
  system('stty', stty_save) if $stdin.tty?
  HammerCLI::EX_OK
end

Private Instance Methods

common_prefix(results) click to toggle source
# File lib/hammer_cli/shell.rb, line 121
def common_prefix(results)
  results.delete_if{ |r| !r[0].start_with?(results[0][0][0]) }.length == results.length
end
complete_proc() click to toggle source
# File lib/hammer_cli/shell.rb, line 125
def complete_proc
  completer = Completer.new(ShellMainCommand)
  Proc.new do |last_word|
    completer.complete(Readline.line_buffer)
  end
end
print_welcome_message() click to toggle source
prompt() click to toggle source
# File lib/hammer_cli/shell.rb, line 112
def prompt
  'hammer> '
end