Module: Bebox::NodeCommands
- Defined in:
- lib/bebox/commands/node_commands.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#generate_node_command(node_command, command, send_command, description) ⇒ Object
For new and set_role commands.
- #list_environments(environments) ⇒ Object
- #load_commands ⇒ Object
- #node_list_command(node_command) ⇒ Object
- #node_remove_command(node_command) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
5 6 7 |
# File 'lib/bebox/commands/node_commands.rb', line 5 def self.extended(base) base.load_commands end |
Instance Method Details
#generate_node_command(node_command, command, send_command, description) ⇒ Object
For new and set_role commands
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bebox/commands/node_commands.rb', line 37 def generate_node_command(node_command, command, send_command, description) node_command.desc description node_command.command command do |generated_command| generated_command.action do |,,args| environment = get_environment() info _('cli.current_environment')%{environment: environment} Bebox::NodeWizard.new.send(send_command, project_root, environment) end end end |
#list_environments(environments) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/bebox/commands/node_commands.rb', line 59 def list_environments(environments) environments.each do |environment| nodes = Node.list(project_root, environment, 'nodes') title _('cli.node.list.env_nodes_title')%{environment: environment} nodes.map{|node| msg("#{node} (#{Bebox::Node.node_provision_state(project_root, environment, node)})")} warn(_('cli.node.list.no_nodes')) if nodes.empty? end end |
#load_commands ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/bebox/commands/node_commands.rb', line 9 def load_commands # Nodes management phase commands desc _('cli.node.desc') command :node do |node_command| node_list_command(node_command) generate_node_command(node_command, :new, :create_new_node, _('cli.node.new.desc')) node_remove_command(node_command) # These commands are available if there is at least one role and one node generate_node_command(node_command, :set_role, :set_role, _('cli.node.set_role.desc')) if (Bebox::Role.roles_count(project_root) > 0 && Bebox::Node.count_all_nodes_by_type(project_root, 'nodes') > 0) end end |
#node_list_command(node_command) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bebox/commands/node_commands.rb', line 21 def node_list_command(node_command) # Node list command node_command.flag :environment, desc: _('cli.node.list.env_flag_desc'), default_value: default_environment node_command.desc _('cli.node.list.desc') node_command.command :list do |node_list_command| node_list_command.switch :all node_list_command.action do |,,args| # Call to list nodes environments = [:all] ? Bebox::Environment.list(project_root) : [get_environment()] list_environments(environments) linebreak end end end |
#node_remove_command(node_command) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bebox/commands/node_commands.rb', line 48 def node_remove_command(node_command) node_command.desc _('cli.node.remove.desc') node_command.command :remove do |node_remove_command| node_remove_command.action do |,,args| environment = get_environment() info _('cli.current_environment')%{environment: environment} Bebox::NodeWizard.new.remove_node(project_root, environment, args.first) end end end |