Module: Bcome::WorkspaceMenu

Included in:
Node::Base
Defined in:
lib/objects/modules/workspace_menu.rb

Instance Method Summary collapse

Instance Method Details

#item_spacing(item) ⇒ Object



23
24
25
# File 'lib/objects/modules/workspace_menu.rb', line 23

def item_spacing(item)
  "\s" * (menu_item_spacing_length - item.length)
end


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/objects/modules/workspace_menu.rb', line 2

def menu
  print "\n\n"
  puts "#{mode} menu".title + "\sfor #{self.class} #{namespace}".resource_value + "\n\n"
  enabled_menu_items.each_with_index do |menu_item, _index|
    item = menu_items[menu_item]
    next if !::Bcome::System::Local.instance.in_console_session? && item[:console_only]
    puts tab_spacing + menu_item.to_s.resource_key + item_spacing(menu_item) + (menu_items[menu_item][:description]).to_s.resource_value
    if item[:usage] || item[:terminal_usage]
      usage_string = ::Bcome::System::Local.instance.in_console_session? ? item[:usage] : "bcome #{keyed_namespace.empty? ? '' : "#{keyed_namespace}:"}#{item[:terminal_usage]}"
      puts tab_spacing + ("\s" * menu_item_spacing_length) + 'usage: '.instructional + usage_string
    end
    puts "\n"
  end

  nil
end


27
28
29
# File 'lib/objects/modules/workspace_menu.rb', line 27

def menu_item_spacing_length
  16
end


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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/objects/modules/workspace_menu.rb', line 35

def menu_items
  {
    ls: {
      description: 'list all available resources',
      console_only: false
    },
    lsa: {
      description: 'list all active resources',
      console_only: true
    },
    workon: {
      description: 'work on specific resources only, inactivating all others from this selection',
      usage: 'workon identifier1, identifier2 ...',
      console_only: true
    },
    disable: {
      description: 'remove a resource from this selection',
      usage: 'disable identifier1, identifier2 ...',
      console_only: true
    },
    enable: {
      description: 're-enable a resource within this selection',
      usage: 'enable identifier1, identifier2 ...',
      console_only: true
    },
    enable!: {
      description: 'enable all resources within this selection',
      console_only: true
    },
    disable!: {
      description: 'disable all resources within this selection',
      console_only: true
    },
    run: {
      description: 'execute a command to be run over ssh against all active resources',
      usage: "run 'command1', 'command2', ...",
      console_only: false,
      terminal_usage: "run 'command1' 'command2' ..."
    },
    interactive: {
      description: 'enter an interactive command session for all active resources',
      console_only: false
    },
    tree: {
      description: 'print a tree view for all resources and their sub-resources',
      console_only: false
    },
    ping: {
      description: 'ping all resources to test connectivity',
      console_only: false
    },
    put: {
      description: 'upload a file or directory using scp',
      usage: "put 'local/path','remote/path'",
      console_only: false,
      terminal_usage: "put 'local/path' 'remote/path'"
    },
    rsync: {
      description: 'upload a file or directory using rsync (faster)',
      usage: "rsync 'local/path','remote/path'",
      console_only: false,
      terminal_usage: "rsync 'local/path' 'remote/path'"
    },
    get: {
      description: 'download a file',
      usage: "get 'remote/path', 'local/path'",
      console_only: false,
      terminal_usage: "get 'remote/path' 'local/path"
    },
    cd: {
      description: 'enter the namespace for a resource from this selection',
      usage: 'cd identifier',
      console_only: true
    },
    save: {
      description: 'Save the current tree state',
      console_only: true
    },
    meta: {
      description: 'Print out all metadata related to this node'
    },
    pack_metadata: {
      description: 'Encrypt your metadata files',
    },
    unpack_metadata: {
      description: 'Decrypt and expose your encrypted metadata files',
    },
    registry: {
      description: 'List all user defined commands present in your registry, and available to this namespace',
      console_only: false
    },
    execute_script: {
      description: 'execute a bash script',
      console_only: false,
      usage: 'execute_script "script_name"',
      terminal_usage: 'execute_script script_name'
    }
  }
end

#modeObject



19
20
21
# File 'lib/objects/modules/workspace_menu.rb', line 19

def mode
  ::Bcome::System::Local.instance.in_console_session? ? 'Console' : 'Terminal'
end

#tab_spacingObject



31
32
33
# File 'lib/objects/modules/workspace_menu.rb', line 31

def tab_spacing
  "\s" * 3
end