From 085f7b1a2aa799665423d9f14541b1b30d4b8468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Wei=C3=9Fe?= Date: Thu, 20 Oct 2022 13:36:20 +0200 Subject: [PATCH] Prompt user for confirmation before overwriting config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Weiße --- cli/internal/cmd/miniup.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cli/internal/cmd/miniup.go b/cli/internal/cmd/miniup.go index 1cc8244d9..03863dc22 100644 --- a/cli/internal/cmd/miniup.go +++ b/cli/internal/cmd/miniup.go @@ -172,6 +172,21 @@ func prepareConfig(cmd *cobra.Command, fileHandler file.Handler) (*config.Config } return config, nil } + if err := cmd.Flags().Set("config", constants.ConfigFilename); err != nil { + return nil, err + } + _, err = fileHandler.Stat(constants.ConfigFilename) + if err == nil { + // config already exists, prompt user to overwrite + cmd.Println("A config file already exists in the current workspace.") + ok, err := askToConfirm(cmd, "Do you want to overwrite it?") + if err != nil { + return nil, err + } + if !ok { + return nil, errors.New("not overwriting existing config") + } + } // download image to current directory if it doesn't exist const imagePath = "./constellation.qcow2" @@ -186,9 +201,6 @@ func prepareConfig(cmd *cobra.Command, fileHandler file.Handler) (*config.Config return nil, fmt.Errorf("checking if image exists: %w", err) } - if err := cmd.Flags().Set("config", constants.ConfigFilename); err != nil { - return nil, err - } config := config.Default() config.RemoveProviderExcept(cloudprovider.QEMU) config.StateDiskSizeGB = 8