runCreate creates a Docker context
(dockerCLI command.Cli, name string, opts createOptions)
| 63 | |
| 64 | // runCreate creates a Docker context |
| 65 | func runCreate(dockerCLI command.Cli, name string, opts createOptions) error { |
| 66 | s := dockerCLI.ContextStore() |
| 67 | err := checkContextNameForCreation(s, name) |
| 68 | if err != nil { |
| 69 | return err |
| 70 | } |
| 71 | switch { |
| 72 | case opts.from == "" && opts.endpoint == nil: |
| 73 | err = createFromExistingContext(s, name, dockerCLI.CurrentContext(), opts) |
| 74 | case opts.from != "": |
| 75 | err = createFromExistingContext(s, name, opts.from, opts) |
| 76 | default: |
| 77 | err = createNewContext(s, name, opts) |
| 78 | } |
| 79 | if err == nil { |
| 80 | _, _ = fmt.Fprintln(dockerCLI.Out(), name) |
| 81 | _, _ = fmt.Fprintf(dockerCLI.Err(), "Successfully created context %q\n", name) |
| 82 | } |
| 83 | return err |
| 84 | } |
| 85 | |
| 86 | func createNewContext(contextStore store.ReaderWriter, name string, opts createOptions) error { |
| 87 | if opts.endpoint == nil { |
searching dependent graphs…