abra/cli/server/remove.go

49 lines
1.2 KiB
Go
Raw Normal View History

package server
import (
2021-10-22 10:01:17 +00:00
"os"
"path/filepath"
"coopcloud.tech/abra/cli/internal"
"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"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var serverRemoveCommand = cli.Command{
Name: "remove",
Aliases: []string{"rm"},
2023-09-07 16:50:25 +00:00
ArgsUsage: "<server>",
Usage: "Remove a managed server",
Description: `Remove a managed server.
2021-10-22 10:01:17 +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{
internal.DebugFlag,
internal.NoInputFlag,
internal.OfflineFlag,
2021-10-22 10:01:17 +00:00
},
Before: internal.SubCommandBefore,
BashComplete: autocomplete.ServerNameComplete,
Action: func(c *cli.Context) error {
serverName := internal.ValidateServer(c)
if err := client.DeleteContext(serverName); err != nil {
logrus.Fatal(err)
}
2021-10-22 10:01:17 +00:00
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
},
}