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



50
51
52
# File 'lib/objects/modules/workspace_menu.rb', line 50

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


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/objects/modules/workspace_menu.rb', line 5

def menu
  print "\n\n"
  puts 'COMMAND MENU'.bc_cyan + "\sfor #{self.class} #{namespace}".resource_value

  grouped_menu_items = menu_items.group_by { |m| m[1][:group] }
  grouped_menu_items.each do |group_key, items|
    # If we're not in a console session, we filter out console only methods
    items = items.reject { |item| item[1][:console_only] } unless ::Bcome::System::Local.instance.in_console_session?

    next if items.empty?

    s_heading = "/ #{menu_group_names[group_key]}"
    print "\n\n" + tab_spacing + s_heading.upcase.bc_cyan
    print item_spacing(s_heading) + ("\s" * 110).to_s.bc_cyan.underline
    print "\n\n"
    print_menu_items(items)
  end

  nil
end


62
63
64
65
66
67
68
69
70
71
72
# File 'lib/objects/modules/workspace_menu.rb', line 62

def menu_group_names
  {
    ssh: 'Ssh',
    informational: 'Informational',
    selection: 'Selections',
    file: 'File & Script',
    navigation: 'Navigational',
    miscellany: 'Miscellaneous',
    command_list: 'Command lists'
  }
end


54
55
56
# File 'lib/objects/modules/workspace_menu.rb', line 54

def menu_item_spacing_length
  16
end


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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/objects/modules/workspace_menu.rb', line 74

def menu_items
  {
    routes: {
      description: 'Print SSH routing tree',
      console_only: false,
      group: :informational
    },
    ls: {
      description: 'list all available namespaces',
      console_only: false,
      group: :informational
    },
    lsa: {
      description: 'list all active namespaces',
      console_only: true,
      group: :informational
    },
    workon: {
      description: 'work on specific namespaces only, inactivating all others from this selection',
      usage: 'workon identifier1, identifier2 ...',
      console_only: true,
      group: :selection
    },
    disable: {
      description: 'remove a namespace from this selection',
      usage: 'disable identifier1, identifier2 ...',
      console_only: true,
      group: :selection
    },
    enable: {
      description: 're-enable a namespace within this selection',
      usage: 'enable identifier1, identifier2 ...',
      console_only: true,
      group: :selection
    },
    enable!: {
      description: 'enable all namespaces within this selection',
      console_only: true,
      group: :selection
    },
    disable!: {
      description: 'disable all namespaces within this selection',
      console_only: true,
      group: :selection
    },
    run: {
      description: 'execute a command to be run over ssh against all active namespaces',
      usage: "run 'command1', 'command2', ...",
      console_only: false,
      terminal_usage: "run 'command1' 'command2' ...",
      group: :ssh
    },
    interactive: {
      description: 'enter an interactive command session for all active namespaces',
      console_only: false,
      group: :ssh
    },
    tree: {
      description: 'print a tree view for all namespaces and their sub-namespaces',
      console_only: false,
      group: :informational
    },
    ping: {
      description: 'ping all namespaces to test connectivity',
      console_only: false,
      group: :ssh
    },
    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'",
      group: :file
    },
    put_str: {
      description: 'Write a file /to/remote/path from a string',
      usage: 'put_str "string" "remote/path"',
      console_only: false,
      terminal_usage: "put_str '<file contents>', 'remote/path'",
      group: :file
    },
    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'",
      group: :file
    },
    cd: {
      description: 'enter a console session for a child namespace from this selection',
      usage: 'cd identifier',
      console_only: true,
      group: :navigation
    },
    quit: {
      description: 'Quit out of bcome',
      usage: 'quit',
      console_only: true,
      group: :navigation
    },
    back: {
      description: 'Go back up a namespace, or quit',
      usage: 'back',
      console_only: true,
      group: :navigation
    },
    meta: {
      description: 'Print out all metadata related to this node',
      group: :informational
    },
    registry: {
      description: 'List all user defined commands present in your registry, and available to this namespace',
      console_only: false,
      group: :command_list
    },
    menu: {
      description: 'List all available commands',
      console_only: false,
      group: :command_list
    },
    execute_script: {
      description: 'execute a bash script',
      console_only: false,
      usage: 'execute_script "script_name"',
      terminal_usage: 'execute_script script_name',
      group: :ssh
    }
  }
end

#modeObject



46
47
48
# File 'lib/objects/modules/workspace_menu.rb', line 46

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


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/objects/modules/workspace_menu.rb', line 26

def print_menu_items(items)
  items.each_with_index do |item, _index|
    key = item[0]
    config = item[1]

    next if !::Bcome::System::Local.instance.in_console_session? && config[:console_only]

    puts tab_spacing + key.to_s.resource_key + item_spacing(key) + (config[:description]).to_s.resource_value
    if config[:usage] || config[:terminal_usage]
      usage_string = if ::Bcome::System::Local.instance.in_console_session?
                       config[:usage]
                     else
                       "bcome #{keyed_namespace.empty? ? '' : "#{keyed_namespace}:"}#{config[:terminal_usage]}"
                     end
      puts tab_spacing + ("\s" * menu_item_spacing_length) + 'usage: '.instructional + usage_string
    end
    puts "\n"
  end
end

#tab_spacingObject



58
59
60
# File 'lib/objects/modules/workspace_menu.rb', line 58

def tab_spacing
  "\s" * 3
end