(dockerCli command.Cli, name string, isCurrent, force bool)
| 49 | } |
| 50 | |
| 51 | func 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. |
| 74 | func checkContextExists(dockerCli command.Cli, name string) error { |
no test coverage detected
searching dependent graphs…