Class: HammerCLI::ShellCommand

Inherits:
AbstractCommand show all
Defined in:
lib/hammer_cli/shell.rb

Constant Summary collapse

DEFAULT_HISTORY_FILE =
"~/.hammer_history"

Instance Attribute Summary

Attributes inherited from AbstractCommand

#context

Instance Method Summary collapse

Methods inherited from AbstractCommand

#adapter, add_option_details_section, add_option_schema, add_sets_help, build_options, #clean_up_context, command_extensions, #exception_handler, extend_help, extend_output_definition, extend_with, family_registry, help, #help, help_extension_blocks, inherited_command_extensions, #initialize, #interactive?, option, option_builder, option_families, option_family, output, #output, #output_definition, output_definition, #parent_command, #parse, #run, use_option, validate_options, #validate_options

Methods included from Subcommand

included

Constructor Details

This class inherits a constructor from HammerCLI::AbstractCommand

Instance Method Details

#executeObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# 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