forked from toolshed/abra
		
	fix: better error handling & proper context deletion for server rm
This commit is contained in:
		| @ -185,12 +185,12 @@ func ValidateSubCmdFlags(c *cli.Context) bool { | ||||
| } | ||||
|  | ||||
| // ValidateServer ensures the server name arg is valid. | ||||
| func ValidateServer(c *cli.Context) (string, error) { | ||||
| func ValidateServer(c *cli.Context) string { | ||||
| 	serverName := c.Args().First() | ||||
|  | ||||
| 	serverNames, err := config.ReadServerNames() | ||||
| 	if err != nil { | ||||
| 		return serverName, err | ||||
| 		logrus.Fatal(err) | ||||
| 	} | ||||
|  | ||||
| 	if serverName == "" && !NoInput { | ||||
| @ -199,17 +199,28 @@ func ValidateServer(c *cli.Context) (string, error) { | ||||
| 			Options: serverNames, | ||||
| 		} | ||||
| 		if err := survey.AskOne(prompt, &serverName); err != nil { | ||||
| 			return serverName, err | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	matched := false | ||||
| 	for _, name := range serverNames { | ||||
| 		if name == serverName { | ||||
| 			matched = true | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if !matched { | ||||
| 		ShowSubcommandHelpAndError(c, errors.New("server doesn't exist?")) | ||||
| 	} | ||||
|  | ||||
| 	if serverName == "" { | ||||
| 		ShowSubcommandHelpAndError(c, errors.New("no server provided")) | ||||
| 	} | ||||
|  | ||||
| 	logrus.Debugf("validated %s as server argument", serverName) | ||||
|  | ||||
| 	return serverName, nil | ||||
| 	return serverName | ||||
| } | ||||
|  | ||||
| // EnsureDNSProvider ensures a DNS provider is chosen. | ||||
|  | ||||
| @ -126,21 +126,24 @@ like tears in rain. | ||||
| 	}, | ||||
| 	Before: internal.SubCommandBefore, | ||||
| 	Action: func(c *cli.Context) error { | ||||
| 		serverName := c.Args().Get(1) | ||||
| 		if serverName != "" { | ||||
| 			var err error | ||||
| 			serverName, err = internal.ValidateServer(c) | ||||
| 			if err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| 			} | ||||
| 		} | ||||
| 		serverName := internal.ValidateServer(c) | ||||
|  | ||||
| 		warnMsg := `Did not pass -s/--server for actual server deletion, prompting! | ||||
|  | ||||
| Abra doesn't currently know if it helped you create this server with one of the | ||||
| 3rd party integrations (e.g. Capsul). You have a choice here to actually, | ||||
| really and finally destroy this server using those integrations. If you want to | ||||
| do this, choose Yes. | ||||
|  | ||||
| If you just want to remove the server config files & context, choose No. | ||||
| ` | ||||
|  | ||||
| 		if !rmServer { | ||||
| 			logrus.Warn("did not pass -s/--server for actual server deletion, prompting") | ||||
| 			logrus.Warn(fmt.Sprintf(warnMsg)) | ||||
|  | ||||
| 			response := false | ||||
| 			prompt := &survey.Confirm{ | ||||
| 				Message: "prompt to actual server deletion?", | ||||
| 				Message: "delete actual live server?", | ||||
| 			} | ||||
| 			if err := survey.AskOne(prompt, &response); err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| @ -164,21 +167,18 @@ like tears in rain. | ||||
| 					logrus.Fatal(err) | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		if serverName != "" { | ||||
| 			if err := client.DeleteContext(serverName); err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| 			if err := os.RemoveAll(filepath.Join(config.SERVERS_DIR, serverName)); err != nil { | ||||
| 				logrus.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| 			logrus.Infof("server at %s has been lost in time, like tears in rain", serverName) | ||||
| 		if err := client.DeleteContext(serverName); err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		if err := os.RemoveAll(filepath.Join(config.SERVERS_DIR, serverName)); err != nil { | ||||
| 			logrus.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		logrus.Infof("server at %s has been lost in time, like tears in rain", serverName) | ||||
|  | ||||
| 		return nil | ||||
| 	}, | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user