feat: WIP server rm command
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
dd86ec4ca8
commit
dfc91a86a1
|
@ -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{
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue