Class: CloudShell

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

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Instance Method Details

#execute_command(command, current_context) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cloud_shell.rb', line 42

def execute_command(command,current_context)
  case command
  when /^ls$/
    puts current_context.to_s
  when /^cd (.*$)/
    new_context = current_context.cd($1)
    if new_context.nil?
      puts "No such key #{$1}"
    else
      current_context = new_context
    end
  when /^cat (.*)$/
    item = current_context.cat($1)
    if item.nil?
      puts "No such item #{$1}"
    else
      puts item.inspect
    end
  when /^help$/
    puts "cat <item> - print the contents of <item> in the current context"
    puts "cd  <item> - change context to the context of <item>"
    puts "cd  ..     - change up one level"
    puts "ls         - list available items in the current context"
    puts "exit	   - exit shell"
  end
  current_context
end

#run(json_file) ⇒ Object

A basic read-only shell-like interface for browsing S3 or Swift JSON objects via fog.to_json using readline



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cloud_shell.rb', line 24

def run(json_file)
  root = JSON.parse(json_file)
  command = nil

  current_context = Context.new(root,nil)

  Readline.completion_proc = proc { |input|
   	current_context.completions(input)
 	  }

  while command != 'exit'
    command = Readline.readline("swift> ",true)
    break if command.nil?
    current_context = execute_command(command.strip,current_context)
  end
end