Class: EnfCli::Shell::Console

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

Class Method Summary collapse

Class Method Details

.execute(input) ⇒ Object



345
346
347
348
349
350
351
352
353
# File 'lib/enfcli.rb', line 345

def execute(input)
  # split on space and = but leave quoted together.
  argv = input.split(/[\s=](?=(?:[^"]|"[^"]*")*$)/)
  # now remove quotes.
  argv.each do |arg|
    arg.gsub!(/\A"|"\Z/, "")
  end
  EnfCli::Shell::CLI.start(argv)
end

.startObject



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'lib/enfcli.rb', line 355

def start
  $stdout.sync = true

  # 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