refactor: dangling else, Sprintf formatting, printing

This commit is contained in:
decentral1se 2021-08-06 12:09:35 +02:00
parent 6732edf8db
commit 36af302d5f
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
1 changed files with 20 additions and 18 deletions

View File

@ -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