Class: EnfCli::Shell::Console

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

Class Method Summary collapse

Class Method Details

.execute(input) ⇒ Object



283
284
285
286
# File 'lib/enfcli.rb', line 283

def execute(input)
  argv = input.split(" ")
  EnfCli::Shell::CLI.start( argv )
end

.start(host, user) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# File 'lib/enfcli.rb', line 288

def start(host, user)
  # Set prompt
  EnfCli::CTX.instance.prompt = user

  # Set host
  EnfCli::CTX.instance.host = host
  
  # Read each line
  comp = proc { |s| Readline::HISTORY.grep(/^#{Regexp.escape(s)}/) }        
  Readline.completion_append_character = " "
  Readline.completion_proc = comp

  stty_save = `stty -g`.chomp
  trap('INT') { system('stty', stty_save); exit }
  
  while input = Readline.readline(EnfCli::CTX.instance.prompt, true)
    break if input == "exit" or input == "\\q" or input == "quit"
    
    # Remove blank lines from history
    Readline::HISTORY.pop if input == ""
    
    execute(input) unless input == ""
  end
end