Class: Retscli::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/retscli/shell.rb

Constant Summary collapse

EXIT_COMMANDS =
['quit', 'exit'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Shell

Returns a new instance of Shell.



10
11
12
13
14
15
16
17
18
# File 'lib/retscli/shell.rb', line 10

def initialize(client)
  @stty_save = `stty -g`.chomp
  setup_readline_autocomplete
  @client = client
  @client.
  @display_adapter = Retscli::DisplayAdapter.new(client)
  @colorer = ::Thor::Shell::Color.new
  
end

Instance Method Details

#execute_shell_command(line, out = $stdout) ⇒ Object

NOTE: this should probably be private, but making it public allowed for easier testing without having to deal with mocking readline. Can we find a better way?



33
34
35
36
37
38
39
# File 'lib/retscli/shell.rb', line 33

def execute_shell_command(line, out=$stdout)
  begin
    Retscli::ShellCommands.start(split_line(line), :display_adapter => @display_adapter)
  rescue => e
    out.puts @colorer.set_color(e.message, :red)
  end
end

#startObject



20
21
22
23
24
25
26
27
28
# File 'lib/retscli/shell.rb', line 20

def start
  while line = readline_with_hist_management
    if EXIT_COMMANDS.include?(line)
      close
    else
      execute_shell_command(line)
    end
  end
end