Class: Menus

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_sys/cli/menus.rb

Class Method Summary collapse

Class Method Details

.get_menu(menu) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/danarchy_sys/cli/menus.rb', line 3

def self.get_menu(menu)
  menus = { 'main' => { 'instance'    => 'Instance Manager',
                        'keypair'     => 'Keypair Manager',
                        'help'        => 'Outputs commands for current the menu level',
                        'exit'        => 'Exit dAnarchy_sys'
                      },
            'instance' => { 'status'  => 'Current running status of instance',
                            'connect' => 'Connect to instance through SSH',
                            'start'   => 'Start a currently stopped instance',
                            'stop'    => 'Stop a currently running instance',
                            'pause'   => 'Pause instance (to RAM)',
                            'unpause' => 'Unpause instance from paused state',
                            'suspend' => 'Suspend Instance (to disk)',
                            'resume'  => 'Resume instance from suspended state',
                            'rebuild' => 'Rebuilds instance with a chosen image',
                            'create'  => 'Create a new instance',
                            'delete'  => 'Delete this instance'
                          },
            'keypair' => { 'info'   => 'View information about this keypair',
                           'create' => 'Create a new keypair',
                           'delete' => 'Delete an existing keypair'
                         }
          }

  menus[menu]
end

.numbered_menu(menu) ⇒ Object



30
31
32
# File 'lib/danarchy_sys/cli/menus.rb', line 30

def self.numbered_menu(menu)
  numbered_menu = Helpers.hash_to_numhash(get_menu(menu))
end


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
63
64
65
# File 'lib/danarchy_sys/cli/menus.rb', line 34

def self.print_menu(menu)
  if menu == 'main'
    puts 'dAnarchy_sys main menu commands:'
    puts 'Enter \'help\' to view available commands or \'exit\' to leave.'
    # print_menu(menu)
  elsif menu == 'instance'
    puts 'Instance Manager commands: '
    puts 'Enter enter \'chooser\' to select an instance, \'help\' to view available commands or \'main\' for the main menu.'
    # print_menu(menu)
  elsif menu == 'keypair'
    puts 'Keypair Manager commands: '
    puts 'Enter enter \'chooser\' to select a keypair, \'help\' to view available commands or \'main\' for the main menu.'
  # print_menu(menu)
  elsif menu == 'storage'
    puts 'Storage Manager commands: '
    puts 'Not yet implemented!'
    return
    # print_menu(menu)
  end

  # numbered_menu = Helpers.hash_to_numhash(menu)
  numbered_menu = numbered_menu(menu)
  menu = get_menu(menu)
  
  fields = PrintFormats.printf_numhash(numbered_menu)

  numbered_menu.each do |id, v|
    v.each do |name, info|
      printf("#{fields}\n", "#{id}.", "#{name}:", info)
    end
  end
end