fix: app rm quitting when there are no secrets/volumes to remove #56
| @ -65,12 +65,6 @@ var appRemoveCommand = &cli.Command{ | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		err = os.Remove(appPath) | ||||
| 		if err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
| 		logrus.Info(fmt.Sprintf("File: %s removed", appPath)) | ||||
|  | ||||
| 		fs := filters.NewArgs() | ||||
| 		fs.Add("name", appName) | ||||
| 		secretList, err := cl.SecretList(ctx, types.SecretListOptions{Filters: fs}) | ||||
| @ -79,35 +73,35 @@ var appRemoveCommand = &cli.Command{ | ||||
| 		} | ||||
|  | ||||
| 		secrets := make(map[string]string) | ||||
| 		var secretNames []string | ||||
| 		if len(secrets) > 0 { | ||||
| 			var secretNames []string | ||||
|  | ||||
| 		for _, cont := range secretList { | ||||
| 			secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's | ||||
| 			secretNames = append(secretNames, cont.Spec.Annotations.Name) | ||||
| 		} | ||||
|  | ||||
| 		var secretNamesToRemove []string | ||||
| 		if !internal.Force { | ||||
| 			secretsPrompt := &survey.MultiSelect{ | ||||
| 				Message: "Which secrets do you want to remove?", | ||||
| 				Options: secretNames, | ||||
| 				Default: secretNames, | ||||
| 			for _, cont := range secretList { | ||||
| 				secrets[cont.Spec.Annotations.Name] = cont.ID // we have to map the names to ID's | ||||
| 				secretNames = append(secretNames, cont.Spec.Annotations.Name) | ||||
| 			} | ||||
| 			if err := survey.AskOne(secretsPrompt, &secretNamesToRemove); err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		for _, name := range secretNamesToRemove { | ||||
| 			err := cl.SecretRemove(ctx, secrets[name]) | ||||
| 			if err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| 			var secretNamesToRemove []string | ||||
| 			if !internal.Force { | ||||
| 				secretsPrompt := &survey.MultiSelect{ | ||||
| 					Message: "Which secrets do you want to remove?", | ||||
| 					Options: secretNames, | ||||
| 					Default: secretNames, | ||||
| 				} | ||||
| 				if err := survey.AskOne(secretsPrompt, &secretNamesToRemove); err != nil { | ||||
| 					logrus.Fatal(err) | ||||
| 				} | ||||
| 			} | ||||
| 			logrus.Info(fmt.Sprintf("Secret: %s removed", name)) | ||||
| 		} | ||||
|  | ||||
| 		if len(secretNamesToRemove) == 0 { | ||||
| 			logrus.Info("No secrets were removed") | ||||
| 			for _, name := range secretNamesToRemove { | ||||
| 				err := cl.SecretRemove(ctx, secrets[name]) | ||||
| 				if err != nil { | ||||
| 					logrus.Fatal(err) | ||||
| 				} | ||||
| 				logrus.Info(fmt.Sprintf("Secret: %s removed", name)) | ||||
| 			} | ||||
| 		} else { | ||||
| 			logrus.Info("No secrets to remove") | ||||
| 		} | ||||
|  | ||||
| 		volumeListOKBody, err := cl.VolumeList(ctx, fs) | ||||
| @ -117,33 +111,43 @@ var appRemoveCommand = &cli.Command{ | ||||
| 		} | ||||
|  | ||||
| 		var vols []string | ||||
| 		for _, vol := range volumeList { | ||||
| 			vols = append(vols, vol.Name) | ||||
| 		} | ||||
|  | ||||
| 		if Volumes { | ||||
| 			var removeVols []string | ||||
| 			if !internal.Force { | ||||
| 				volumesPrompt := &survey.MultiSelect{ | ||||
| 					Message: "Which volumes do you want to remove?", | ||||
| 					Options: vols, | ||||
| 					Default: vols, | ||||
| 				} | ||||
| 				if err := survey.AskOne(volumesPrompt, &removeVols); err != nil { | ||||
| 					logrus.Fatal(err) | ||||
| 				} | ||||
| 		if len(vols) > 0 { | ||||
| 			for _, vol := range volumeList { | ||||
| 				vols = append(vols, vol.Name) | ||||
| 			} | ||||
| 			for _, vol := range removeVols { | ||||
| 				err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing | ||||
| 				if err != nil { | ||||
| 					logrus.Fatal(err) | ||||
|  | ||||
| 			if Volumes { | ||||
| 				var removeVols []string | ||||
| 				if !internal.Force { | ||||
| 					volumesPrompt := &survey.MultiSelect{ | ||||
| 						Message: "Which volumes do you want to remove?", | ||||
| 						Options: vols, | ||||
| 						Default: vols, | ||||
| 					} | ||||
| 					if err := survey.AskOne(volumesPrompt, &removeVols); err != nil { | ||||
| 						logrus.Fatal(err) | ||||
| 					} | ||||
| 				} | ||||
| 				logrus.Info(fmt.Sprintf("Volume %s removed", vol)) | ||||
| 				for _, vol := range removeVols { | ||||
| 					err := cl.VolumeRemove(ctx, vol, internal.Force) // last argument is for force removing | ||||
| 					if err != nil { | ||||
| 						logrus.Fatal(err) | ||||
| 					} | ||||
| 					logrus.Info(fmt.Sprintf("Volume %s removed", vol)) | ||||
| 				} | ||||
| 			} else { | ||||
| 				logrus.Info("No volumes were removed") | ||||
| 			} | ||||
| 		} else { | ||||
| 			logrus.Info("No volumes were removed") | ||||
| 			logrus.Info("No volumes to remove") | ||||
| 		} | ||||
|  | ||||
| 		err = os.Remove(appPath) | ||||
| 		if err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
| 		logrus.Info(fmt.Sprintf("File: %s removed", appPath)) | ||||
|  | ||||
| 		return nil | ||||
| 	}, | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user