From 5b7cb5d7ed249a757e28927f5df962a24061a4d2 Mon Sep 17 00:00:00 2001 From: Luca Stocchi Date: Mon, 27 Jan 2025 12:14:35 +0100 Subject: [PATCH] add rm action it adds a basic rm action which do not accept any args. As only the default macadam machine can be init, the rm only works with it. Signed-off-by: Luca Stocchi --- cmd/macadam/rm.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 cmd/macadam/rm.go diff --git a/cmd/macadam/rm.go b/cmd/macadam/rm.go new file mode 100644 index 00000000..75503b86 --- /dev/null +++ b/cmd/macadam/rm.go @@ -0,0 +1,38 @@ +package main + +import ( + "github.com/cfergeau/macadam/cmd/macadam/registry" + macadam "github.com/cfergeau/macadam/pkg/machinedriver" + "github.com/containers/podman/v5/pkg/machine" + "github.com/spf13/cobra" +) + +var ( + rmCmd = &cobra.Command{ + Use: "rm [options]", + Short: "Remove an existing machine", + Long: "Remove a managed virtual machine ", + RunE: rm, + Args: cobra.MaximumNArgs(0), + Example: `macadam rm`, + } +) + +var ( + destroyOptions machine.RemoveOptions +) + +func init() { + registry.Commands = append(registry.Commands, registry.CliCommand{ + Command: rmCmd, + }) +} + +func rm(_ *cobra.Command, args []string) error { + driver, err := macadam.GetDriverByMachineName(defaultMachineName) + if err != nil { + return nil + } + + return driver.Remove() +}