feat: WIP server rm command
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Roxie Gibson 2021-07-22 17:38:44 +01:00
parent dd86ec4ca8
commit dfc91a86a1
Signed by untrusted user: roxxers
GPG Key ID: 5D0140EDEE123F4D
2 changed files with 27 additions and 1 deletions

View File

@ -82,9 +82,16 @@ var serverNewCommand = &cli.Command{
var serverRemoveCommand = &cli.Command{
Name: "remove",
Aliases: []string{"rm"},
Aliases: []string{"rm", "delete"},
Usage: "Remove server <host>",
HideHelp: true,
Action: func(c *cli.Context) error {
server := c.Args().First()
if err := client.DeleteContext(server); err != nil {
logrus.Fatal(err)
}
return nil
},
}
var serverInitCommand = &cli.Command{

View File

@ -57,6 +57,25 @@ func createContext(name string, host string) error {
return nil
}
func DeleteContext(name string) error {
if name == "default" {
return errors.New("context 'default' cannot be removed")
}
if _, err := GetContext(name); err != nil {
return err
}
// remove any context that might be loaded
// TODO: Check if the context we are removing is the active one rather than doing it all the time
cfg := dConfig.LoadDefaultConfigFile(nil)
cfg.CurrentContext = ""
if err := cfg.Save(); err != nil {
return err
}
return NewDefaultDockerContextStore().Remove(name)
}
func GetContext(contextName string) (contextStore.Metadata, error) {
ctx, err := NewDefaultDockerContextStore().GetMetadata(contextName)
if err != nil {