diff --git a/src/cluster/delete.cr b/src/cluster/delete.cr index 8c9e86f6..35871171 100644 --- a/src/cluster/delete.cr +++ b/src/cluster/delete.cr @@ -20,27 +20,30 @@ class Cluster::Delete private getter settings : Configuration::Main do configuration.settings end + private getter force : Bool = false private property instance_deletors : Array(Hetzner::Instance::Delete) = [] of Hetzner::Instance::Delete - def initialize(@configuration) + def initialize(@configuration, @force) end def run - print "Please enter the cluster name to confirm that you want to delete it: " - input = gets - - if input.try(&.strip) != settings.cluster_name - puts - puts "Cluster name '#{input.try(&.strip)}' does not match expected '#{settings.cluster_name}'. Aborting deletion.".colorize(:red) - puts - exit 1 - end + unless force + print "Please enter the cluster name to confirm that you want to delete it: " + input = gets + + if input.try(&.strip) != settings.cluster_name + puts + puts "Cluster name '#{input.try(&.strip)}' does not match expected '#{settings.cluster_name}'. Aborting deletion.".colorize(:red) + puts + exit 1 + end - if settings.protect_against_deletion - puts - puts "WARNING: Cluster cannot be deleted. If you are sure about this, disable the protection by setting `protect_against_deletion` to `false` in the config file. Aborting deletion.".colorize(:red) - puts - exit 1 + if settings.protect_against_deletion + puts + puts "WARNING: Cluster cannot be deleted. If you are sure about this, disable the protection by setting `protect_against_deletion` to `false` in the config file. Aborting deletion.".colorize(:red) + puts + exit 1 + end end delete_resources diff --git a/src/hetzner-k3s.cr b/src/hetzner-k3s.cr index d48192f0..8010ccfd 100644 --- a/src/hetzner-k3s.cr +++ b/src/hetzner-k3s.cr @@ -37,11 +37,17 @@ module Hetzner::K3s short: "c", required: true + define_flag force : Bool, + description: "Force deletion of the cluster without any prompts", + long: "force", + required: false, + default: false + def run configuration = Configuration::Loader.new(flags.configuration_file_path, nil) configuration.validate(:delete) - Cluster::Delete.new(configuration: configuration).run + Cluster::Delete.new(configuration: configuration, force: flags.force).run end end