Sha256: e90fa5b435d4f4db09093f00b3ac3caab1362aeadaed166b9cfde44bab074efe

Contents?: true

Size: 1.87 KB

Versions: 45

Compression:

Stored size: 1.87 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 questions"

    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)
      case servers.size
      when 0
        abort "Master not found in configuration"
      when 1
        config.servers.delete(config.servers.delete(servers.first))
        puts "Removed Master '#{servers.first.name}'"
      else
        unless self.force?
          abort("Aborted") unless prompt.yes?("Remove #{servers.size} masters from configuration?")
        end
        config.servers.delete_if {|s| servers.include?(s) }
        puts "Removed #{servers.size} masters from configuration"
      end
      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

45 entries across 45 versions & 1 rubygems

Version Path
kontena-cli-1.1.0.pre1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.6 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.6.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.5 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.5.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.5.pre1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.4 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.4.rc2 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.4.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.3 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.3.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.2 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.2.rc2 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.2.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.2.pre1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.1.rc3 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.1.rc2 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.1.rc1 lib/kontena/cli/master/remove_command.rb
kontena-cli-1.0.0 lib/kontena/cli/master/remove_command.rb