2021-08-02 01:10:41 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2021-10-22 10:01:17 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-08-03 11:57:12 +00:00
|
|
|
"coopcloud.tech/abra/cli/internal"
|
2023-02-17 09:10:48 +00:00
|
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
2021-09-05 19:37:03 +00:00
|
|
|
"coopcloud.tech/abra/pkg/client"
|
2021-10-22 10:01:17 +00:00
|
|
|
"coopcloud.tech/abra/pkg/config"
|
2021-08-02 01:10:41 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2022-01-18 13:13:20 +00:00
|
|
|
"github.com/urfave/cli"
|
2021-08-02 01:10:41 +00:00
|
|
|
)
|
|
|
|
|
2022-01-18 13:13:20 +00:00
|
|
|
var serverRemoveCommand = cli.Command{
|
2021-11-03 07:34:36 +00:00
|
|
|
Name: "remove",
|
|
|
|
Aliases: []string{"rm"},
|
2023-09-07 16:50:25 +00:00
|
|
|
ArgsUsage: "<server>",
|
2021-11-03 07:34:36 +00:00
|
|
|
Usage: "Remove a managed server",
|
2023-09-14 08:02:43 +00:00
|
|
|
Description: `Remove a managed server.
|
2021-10-22 10:01:17 +00:00
|
|
|
|
2023-09-14 08:02:43 +00:00
|
|
|
Abra will remove the internal bookkeeping (~/.abra/servers/...) and underlying
|
|
|
|
client connection context. This server will then be lost in time, like tears in
|
|
|
|
rain.
|
2021-09-04 23:34:56 +00:00
|
|
|
`,
|
2021-10-22 10:01:17 +00:00
|
|
|
Flags: []cli.Flag{
|
2022-01-18 13:13:20 +00:00
|
|
|
internal.DebugFlag,
|
|
|
|
internal.NoInputFlag,
|
2023-07-26 06:16:07 +00:00
|
|
|
internal.OfflineFlag,
|
2021-10-22 10:01:17 +00:00
|
|
|
},
|
2023-02-17 09:10:48 +00:00
|
|
|
Before: internal.SubCommandBefore,
|
|
|
|
BashComplete: autocomplete.ServerNameComplete,
|
2021-08-02 01:10:41 +00:00
|
|
|
Action: func(c *cli.Context) error {
|
2022-02-24 14:57:52 +00:00
|
|
|
serverName := internal.ValidateServer(c)
|
|
|
|
|
|
|
|
if err := client.DeleteContext(serverName); err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-10-22 10:01:17 +00:00
|
|
|
|
2022-02-24 14:57:52 +00:00
|
|
|
if err := os.RemoveAll(filepath.Join(config.SERVERS_DIR, serverName)); err != nil {
|
|
|
|
logrus.Fatal(err)
|
2022-01-02 00:52:49 +00:00
|
|
|
}
|
2021-09-10 13:04:01 +00:00
|
|
|
|
2022-02-24 14:57:52 +00:00
|
|
|
logrus.Infof("server at %s has been lost in time, like tears in rain", serverName)
|
|
|
|
|
2021-08-02 01:10:41 +00:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|