From 36af302d5fc71e4e17dff6aed50920abc4a3465f Mon Sep 17 00:00:00 2001 From: decentral1se Date: Fri, 6 Aug 2021 12:09:35 +0200 Subject: [PATCH] refactor: dangling else, Sprintf formatting, printing --- cli/app/remove.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/cli/app/remove.go b/cli/app/remove.go index 9bc4d0dd..e2092c22 100644 --- a/cli/app/remove.go +++ b/cli/app/remove.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "os" - "strings" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/client" @@ -39,6 +38,7 @@ var appRemoveCommand = &cli.Command{ if appName == "" { internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!")) } + if !internal.Force { response := false prompt := &survey.Confirm{ @@ -49,24 +49,25 @@ var appRemoveCommand = &cli.Command{ return errors.New("User aborted app removal") } } + appFiles, err := config.LoadAppFiles("") if err != nil { logrus.Fatal(err) } + appPath := appFiles[appName].Path - fmt.Println(appFiles) host := appFiles[appName].Server ctx := context.Background() cl, err := client.NewClientWithContext(host) if err != nil { logrus.Fatal(err) } + err = os.Remove(appPath) if err != nil { logrus.Fatal(err) - } else { - logrus.Info(fmt.Sprintf("File: %s removed", appPath)) } + logrus.Info(fmt.Sprintf("File: %s removed", appPath)) fs := filters.NewArgs() fs.Add("name", appName) @@ -74,17 +75,17 @@ var appRemoveCommand = &cli.Command{ if err != nil { logrus.Fatal(err) } + secrets := make(map[string]string) secretNames := []string{} + for _, cont := range secretList { - secrets[cont.Spec.Annotations.Name] = cont.ID //we have to map the names to ID's + secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's secretNames = append(secretNames, cont.Spec.Annotations.Name) } - secretNamesToRemove := []string{} - if internal.Force { - secretNamesToRemove = secretNames - } else { + secretNamesToRemove := secretNames + if !internal.Force { secretsPrompt := &survey.MultiSelect{ Message: "Which secrets do you want to remove?", Options: secretNames, @@ -97,9 +98,12 @@ var appRemoveCommand = &cli.Command{ err := cl.SecretRemove(ctx, secrets[name]) if err != nil { logrus.Fatal(err) - } else { - logrus.Info(fmt.Sprintf("Secret: %s removed", name)) } + logrus.Info(fmt.Sprintf("Secret: %s removed", name)) + } + + if len(secretNamesToRemove) == 0 { + logrus.Info("No secrets were removed") } volumeListOKBody, err := cl.VolumeList(ctx, fs) @@ -107,16 +111,15 @@ var appRemoveCommand = &cli.Command{ if err != nil { logrus.Fatal(err) } + vols := []string{} for _, vol := range volumeList { vols = append(vols, vol.Name) } if Volumes { - removeVols := []string{} - if internal.Force { - removeVols = vols - } else { + removeVols := vols + if !internal.Force { volumesPrompt := &survey.MultiSelect{ Message: "Which volumes do you want to remove?", Options: vols, @@ -128,12 +131,11 @@ var appRemoveCommand = &cli.Command{ err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing if err != nil { logrus.Fatal(err) - } else { - logrus.Info("Volume " + vol + " removed") } + logrus.Info(fmt.Sprintf("Volume %s removed", vol)) } } else { - logrus.Info("No volumes were removed. Volumes left: " + strings.Join(vols, ", ")) + logrus.Info("No volumes were removed") } return nil