Class: SakaiInfo::CLI::Shell
- Inherits:
-
Object
- Object
- SakaiInfo::CLI::Shell
- Defined in:
- lib/sakai-info/cli/shell.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_shell_command_count(argv) ⇒ Object
- #_shell_command_quit(argv) ⇒ Object (also: #_shell_command_exit)
- #_shell_command_user(argv) ⇒ Object
- #context_prompt ⇒ Object
-
#initialize ⇒ Shell
constructor
A new instance of Shell.
- #prompt ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize ⇒ Shell
Returns a new instance of Shell.
19 20 21 22 23 |
# File 'lib/sakai-info/cli/shell.rb', line 19 def initialize @context = nil @context_history = [] @running = true end |
Class Method Details
Instance Method Details
#_shell_command_count(argv) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# 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_quit(argv) ⇒ Object Also known as: _shell_command_exit
64 65 66 |
# File 'lib/sakai-info/cli/shell.rb', line 64 def _shell_command_quit(argv) @running = false end |
#_shell_command_user(argv) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# 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 ⇒ Object
25 26 27 28 29 30 31 32 33 |
# 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 ⇒ Object
35 36 37 38 |
# File 'lib/sakai-info/cli/shell.rb', line 35 def prompt print "sin#{context_prompt}> ";STDOUT.flush gets end |
#run ⇒ Object
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/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 |