MCPcopy Index your code
hub / github.com/docker/cli / doRemove

Function doRemove

cli/command/context/remove.go:51–71  ·  view source on GitHub ↗
(dockerCli command.Cli, name string, isCurrent, force bool)

Source from the content-addressed store, hash-verified

49}
50
51func doRemove(dockerCli command.Cli, name string, isCurrent, force bool) error {
52 if isCurrent {
53 if !force {
54 return fmt.Errorf("context %q is in use, set -f flag to force remove", name)
55 }
56 // fallback to DOCKER_HOST
57 cfg := dockerCli.ConfigFile()
58 cfg.CurrentContext = ""
59 if err := cfg.Save(); err != nil {
60 return err
61 }
62 }
63
64 if !force {
65 // TODO(thaJeztah): instead of checking before removing, can we make ContextStore().Remove() return a proper errdef and ignore "not found" errors?
66 if err := checkContextExists(dockerCli, name); err != nil {
67 return err
68 }
69 }
70 return dockerCli.ContextStore().Remove(name)
71}
72
73// checkContextExists returns an error if the context directory does not exist.
74func checkContextExists(dockerCli command.Cli, name string) error {

Callers 1

runRemoveFunction · 0.85

Calls 5

checkContextExistsFunction · 0.85
ConfigFileMethod · 0.65
SaveMethod · 0.65
RemoveMethod · 0.65
ContextStoreMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…