(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 42 | } |
| 43 | |
| 44 | func commitCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 45 | options := commitOptions{ |
| 46 | ProjectOptions: p, |
| 47 | } |
| 48 | cmd := &cobra.Command{ |
| 49 | Use: "commit [OPTIONS] SERVICE [REPOSITORY[:TAG]]", |
| 50 | Short: "Create a new image from a service container's changes", |
| 51 | Args: cobra.RangeArgs(1, 2), |
| 52 | PreRunE: Adapt(func(ctx context.Context, args []string) error { |
| 53 | options.service = args[0] |
| 54 | if len(args) > 1 { |
| 55 | options.reference = args[1] |
| 56 | } |
| 57 | |
| 58 | return nil |
| 59 | }), |
| 60 | RunE: Adapt(func(ctx context.Context, args []string) error { |
| 61 | return runCommit(ctx, dockerCli, backendOptions, options) |
| 62 | }), |
| 63 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 64 | } |
| 65 | |
| 66 | flags := cmd.Flags() |
| 67 | flags.IntVar(&options.index, "index", 0, "index of the container if service has multiple replicas.") |
| 68 | |
| 69 | flags.BoolVarP(&options.pause, "pause", "p", true, "Pause container during commit") |
| 70 | flags.StringVarP(&options.comment, "message", "m", "", "Commit message") |
| 71 | flags.StringVarP(&options.author, "author", "a", "", `Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")`) |
| 72 | options.changes = opts.NewListOpts(nil) |
| 73 | flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image") |
| 74 | |
| 75 | return cmd |
| 76 | } |
| 77 | |
| 78 | func runCommit(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, options commitOptions) error { |
| 79 | projectName, err := options.toProjectName(ctx, dockerCli) |
no test coverage detected