Sha256: 5ac3c91d3289a10c414067b6be61535df0eee37215db3d024363657458f260f0

Contents?: true

Size: 1.67 KB

Versions: 106

Compression:

Stored size: 1.67 KB

Contents

module Kontena::Cli::Master
  class RemoveCommand < Kontena::Command
    include Kontena::Cli::Common

    parameter '[NAME]', "Master name"

    banner "Note: This command only removes the master from your local configuration file"

    option '--force', :flag, "Don't ask for confirmation", attribute_name: :forced

    def run_interactive
      selections = prompt.multi_select("Select masters to remove from configuration file:") do |menu|
        config.servers.each do |server|
          menu.choice " #{pastel.green("* ") if config.current_server == server.name}#{server.name} (#{server.username || 'unknown'} @ #{server.url})", server
        end
      end
      if selections.empty?
        puts "No masters selected"
        exit 0
      end
      delete_servers(selections)
    end

    def delete_servers(servers)
      abort "Master not found in configuration" if servers.empty?

      unless forced?
        puts "Removing #{servers.size} master#{"s" if servers.size > 1} from configuration"
        confirm
      end

      config.servers.delete_if {|s| servers.include?(s) }

      unless config.find_server(config.current_server)
        puts
        puts "Current master was removed, to select a new current master use:"
        puts "  " + pastel.green.on_black("  kontena master use <master_name>  ")
        puts "Or log into another master by using:"
        puts "  " + pastel.green.on_black("  kontena master login <master_url>  ")
        config.current_server = nil
      end

      config.write
    end

    def execute
      if self.name.nil?
        run_interactive
      else
        delete_servers(config.servers.select {|s| s.name == self.name})
      end
    end
  end
end

Version data entries

106 entries across 106 versions & 2 rubygems

Version Path
kontena-cli-1.1.2.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.1.1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.1.1.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.1.0 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.1.0.rc2 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.1.0.rc1 lib/kontena/cli/master/remove_command.rb