Class: Zillabyte::Command::Repl

Inherits:
Base
  • Object
show all
Defined in:
lib/zillabyte/cli/repl.rb

Overview

REPL console for zillabyte commands

Constant Summary

Constants inherited from Base

Base::META_COLUMNS

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #initialize, namespace

Methods included from Helpers

#app, #ask, #command, #create_git_remote, #display, #error, #extract_app_from_git_config, #extract_app_in_dir, #format_with_bang, #friendly_dir, #get_flow_ui_link, #get_info, #get_rich_info, #git, #handle_downloading_manifest, #has_git?, #longest, #read_multiline, #truncate_message, #version_okay?, #with_tty

Constructor Details

This class inherits a constructor from Zillabyte::Command::Base

Instance Method Details

#indexObject

repl

Start a console session for zillabyte.

–quiet # HIDDEN –history HISTORY # HIDDEN hack to allow history for readline



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/zillabyte/cli/repl.rb', line 13

def index
  require("readline")
  require("shellwords")
  if !options[:quiet]
    Zillabyte::Command.load("version")
    Zillabyte::Command.run("version")
    display "Type q,exit or Ctrl+D to quit\n\n"
  end
  server = `echo $ZILLABYTE_API_HOST` || ""
  prompt = ""
  if server && server.chomp.length > 0
    prompt = "#{server.chomp} " 
  end
  prompt += "zillabyte $ "
  if options[:history]
    #p options[:history]
    history = JSON.parse(options[:history])
    history.last(50).each do |his|
      # TODO: Handle single quotes ??
      Readline::HISTORY << his
    end
  end
  # TODO: Add tab completion for basic commands, app/dataset names etc.
  buf = ""
  while cmd = Readline.readline(prompt, true)
    if cmd && cmd.length > 0
      if cmd.downcase == "exit" || cmd.downcase == "q"
        display "" # TODO Make Ctrl+D print a newline too
        return
      else
        buf << cmd
        begin
          args = Shellwords.split(buf)
          raise if args.empty?()
          command = args.shift
          buf = ""
          begin
            pid = fork() do
              Zillabyte::Command.load(command)
              Zillabyte::Command.run(command, args)
            end
          ensure
            Process.waitpid(pid)
          end
        rescue => e
        end
      end
    end
  end
end