package server

import (
	"errors"

	"coopcloud.tech/abra/cli/internal"
	"coopcloud.tech/abra/pkg/client"
	"github.com/sirupsen/logrus"
	"github.com/urfave/cli/v2"
)

var serverRemoveCommand = &cli.Command{
	Name:    "remove",
	Aliases: []string{"rm"},
	Usage:   "Remove a server",
	Description: `
This does not destroy the actual server. It simply removes it from Abra
internal bookkeeping so that it is not managed any more.
`,
	HideHelp: true,
	Action: func(c *cli.Context) error {
		server := c.Args().First()
		if server == "" {
			internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
		}
		if err := client.DeleteContext(server); err != nil {
			logrus.Fatal(err)
		}
		return nil
	},
}