refactor: dangling else, Sprintf formatting, printing
This commit is contained in:
parent
6732edf8db
commit
36af302d5f
|
@ -5,7 +5,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/client"
|
"coopcloud.tech/abra/client"
|
||||||
|
@ -39,6 +38,7 @@ var appRemoveCommand = &cli.Command{
|
||||||
if appName == "" {
|
if appName == "" {
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!"))
|
internal.ShowSubcommandHelpAndError(c, errors.New("No app name provided!"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Force {
|
if !internal.Force {
|
||||||
response := false
|
response := false
|
||||||
prompt := &survey.Confirm{
|
prompt := &survey.Confirm{
|
||||||
|
@ -49,24 +49,25 @@ var appRemoveCommand = &cli.Command{
|
||||||
return errors.New("User aborted app removal")
|
return errors.New("User aborted app removal")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appFiles, err := config.LoadAppFiles("")
|
appFiles, err := config.LoadAppFiles("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
appPath := appFiles[appName].Path
|
appPath := appFiles[appName].Path
|
||||||
fmt.Println(appFiles)
|
|
||||||
host := appFiles[appName].Server
|
host := appFiles[appName].Server
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cl, err := client.NewClientWithContext(host)
|
cl, err := client.NewClientWithContext(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = os.Remove(appPath)
|
err = os.Remove(appPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
} else {
|
|
||||||
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
|
|
||||||
}
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("File: %s removed", appPath))
|
||||||
|
|
||||||
fs := filters.NewArgs()
|
fs := filters.NewArgs()
|
||||||
fs.Add("name", appName)
|
fs.Add("name", appName)
|
||||||
|
@ -74,17 +75,17 @@ var appRemoveCommand = &cli.Command{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
secrets := make(map[string]string)
|
secrets := make(map[string]string)
|
||||||
secretNames := []string{}
|
secretNames := []string{}
|
||||||
|
|
||||||
for _, cont := range secretList {
|
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)
|
secretNames = append(secretNames, cont.Spec.Annotations.Name)
|
||||||
}
|
}
|
||||||
secretNamesToRemove := []string{}
|
|
||||||
|
|
||||||
if internal.Force {
|
secretNamesToRemove := secretNames
|
||||||
secretNamesToRemove = secretNames
|
if !internal.Force {
|
||||||
} else {
|
|
||||||
secretsPrompt := &survey.MultiSelect{
|
secretsPrompt := &survey.MultiSelect{
|
||||||
Message: "Which secrets do you want to remove?",
|
Message: "Which secrets do you want to remove?",
|
||||||
Options: secretNames,
|
Options: secretNames,
|
||||||
|
@ -97,9 +98,12 @@ var appRemoveCommand = &cli.Command{
|
||||||
err := cl.SecretRemove(ctx, secrets[name])
|
err := cl.SecretRemove(ctx, secrets[name])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
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)
|
volumeListOKBody, err := cl.VolumeList(ctx, fs)
|
||||||
|
@ -107,16 +111,15 @@ var appRemoveCommand = &cli.Command{
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vols := []string{}
|
vols := []string{}
|
||||||
for _, vol := range volumeList {
|
for _, vol := range volumeList {
|
||||||
vols = append(vols, vol.Name)
|
vols = append(vols, vol.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
if Volumes {
|
if Volumes {
|
||||||
removeVols := []string{}
|
removeVols := vols
|
||||||
if internal.Force {
|
if !internal.Force {
|
||||||
removeVols = vols
|
|
||||||
} else {
|
|
||||||
volumesPrompt := &survey.MultiSelect{
|
volumesPrompt := &survey.MultiSelect{
|
||||||
Message: "Which volumes do you want to remove?",
|
Message: "Which volumes do you want to remove?",
|
||||||
Options: vols,
|
Options: vols,
|
||||||
|
@ -128,12 +131,11 @@ var appRemoveCommand = &cli.Command{
|
||||||
err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing
|
err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
} else {
|
|
||||||
logrus.Info("Volume " + vol + " removed")
|
|
||||||
}
|
}
|
||||||
|
logrus.Info(fmt.Sprintf("Volume %s removed", vol))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
logrus.Info("No volumes were removed. Volumes left: " + strings.Join(vols, ", "))
|
logrus.Info("No volumes were removed")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue