1717package context
1818
1919import (
20- "errors"
21- "fmt"
22-
23- "github.com/docker/compose/v2/cmd/formatter"
24- "github.com/hashicorp/go-multierror"
20+ "github.com/docker/compose-cli/cli/mobycli"
2521 "github.com/spf13/cobra"
26-
27- apicontext "github.com/docker/compose-cli/api/context"
28- "github.com/docker/compose-cli/api/context/store"
2922)
3023
3124type removeOpts struct {
@@ -40,43 +33,11 @@ func removeCommand() *cobra.Command {
4033 Aliases : []string {"remove" },
4134 Args : cobra .MinimumNArgs (1 ),
4235 RunE : func (cmd * cobra.Command , args []string ) error {
43- return runRemove (args , opts .force )
36+ mobycli .Exec (cmd .Root ())
37+ return nil
4438 },
4539 }
4640 cmd .Flags ().BoolVarP (& opts .force , "force" , "f" , false , "Force removing current context" )
4741
4842 return cmd
4943}
50-
51- func runRemove (args []string , force bool ) error {
52- currentContext := apicontext .Current ()
53- s := store .Instance ()
54-
55- var errs * multierror.Error
56- for _ , contextName := range args {
57- if currentContext == contextName {
58- if force {
59- if err := runUse ("default" ); err != nil {
60- errs = multierror .Append (errs , errors .New ("cannot delete current context" ))
61- } else {
62- errs = removeContext (s , contextName , errs )
63- }
64- } else {
65- errs = multierror .Append (errs , errors .New ("cannot delete current context" ))
66- }
67- } else {
68- errs = removeContext (s , contextName , errs )
69- }
70- }
71- formatter .SetMultiErrorFormat (errs )
72- return errs .ErrorOrNil ()
73- }
74-
75- func removeContext (s store.Store , n string , errs * multierror.Error ) * multierror.Error {
76- if err := s .Remove (n ); err != nil {
77- errs = multierror .Append (errs , err )
78- } else {
79- fmt .Println (n )
80- }
81- return errs
82- }
0 commit comments