1
0

rm.go 749 B

123456789101112131415161718192021222324252627282930313233343536
  1. package context
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/spf13/cobra"
  6. "github.com/docker/api/context/store"
  7. "github.com/docker/api/multierror"
  8. )
  9. func removeCommand() *cobra.Command {
  10. return &cobra.Command{
  11. Use: "rm CONTEXT [CONTEXT...]",
  12. Short: "Remove one or more contexts",
  13. Aliases: []string{"remove"},
  14. Args: cobra.MinimumNArgs(1),
  15. RunE: func(cmd *cobra.Command, args []string) error {
  16. return runRemove(cmd.Context(), args)
  17. },
  18. }
  19. }
  20. func runRemove(ctx context.Context, args []string) error {
  21. s := store.ContextStore(ctx)
  22. var errs *multierror.Error
  23. for _, n := range args {
  24. if err := s.Remove(n); err != nil {
  25. errs = multierror.Append(errs, err)
  26. } else {
  27. fmt.Println(n)
  28. }
  29. }
  30. return errs.ErrorOrNil()
  31. }