class SakaiInfo::CLI::Shell

Public Class Methods

new() click to toggle source
# File lib/sakai-info/cli/shell.rb, line 19
def initialize
  @context = nil
  @context_history = []
  @running = true
end
process(args, flags) click to toggle source
# File lib/sakai-info/cli/shell.rb, line 15
def self.process(args, flags)
  Shell.new.run
end

Public Instance Methods

_shell_command_count(argv) click to toggle source
# File lib/sakai-info/cli/shell.rb, line 70
def _shell_command_count(argv)
  case argv[0].downcase
  when /^users?$/
    puts User.count
  when /^sites?$/
    puts Site.count
  else
    STDERR.puts("ERROR: unrecognized object type")
  end
end
_shell_command_exit(argv)
Alias for: _shell_command_quit
_shell_command_quit(argv) click to toggle source
# File lib/sakai-info/cli/shell.rb, line 64
def _shell_command_quit(argv)
  @running = false
end
Also aliased as: _shell_command_exit
_shell_command_user(argv) click to toggle source
# File lib/sakai-info/cli/shell.rb, line 81
def _shell_command_user(argv)
  user = nil
  begin
    user = User.find(argv[0])
  rescue ObjectNotFoundException => e
    STDERR.puts "ERROR: could not find user '#{argv[0]}'"
    STDERR.puts "       #{e}"
    return
  end

  return if user.nil?

  puts user.to_yaml(:shell)
end
context_prompt() click to toggle source
# File lib/sakai-info/cli/shell.rb, line 25
def context_prompt
  if @context.nil?
    "[-]"
  else
    # TODO: implement ShellContext object
    #@context.brief_name
    "[!]"
  end
end
prompt() click to toggle source
# File lib/sakai-info/cli/shell.rb, line 35
def prompt
  print "sin#{context_prompt}> ";STDOUT.flush
  gets
end
run() click to toggle source
# File lib/sakai-info/cli/shell.rb, line 40
def run
  while @running do
    input = prompt

    # a ctrl-D sends nil
    if input.nil?
      puts "exit"
      break
    end

    argv = input.chomp.split(/ +/)
    command = argv.shift.downcase
    method_name = ("_shell_command_#{command}").to_sym

    if Shell.method_defined? method_name
      self.method(method_name).call(argv)
    else
      STDERR.puts "ERROR: unknown command '#{command}'"
    end
  end

  # TODO: any additional cleanup here
end