@@ -2,6 +2,7 @@ package container
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67
78 "github.com/docker/cli/cli"
@@ -17,6 +18,7 @@ type commitOptions struct {
1718 reference string
1819
1920 pause bool
21+ noPause bool
2022 comment string
2123 author string
2224 changes opts.ListOpts
@@ -35,6 +37,12 @@ func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
3537 if len (args ) > 1 {
3638 options .reference = args [1 ]
3739 }
40+ if cmd .Flag ("pause" ).Changed {
41+ if cmd .Flag ("no-pause" ).Changed {
42+ return errors .New ("conflicting options: --no-pause and --pause cannot be used together" )
43+ }
44+ options .noPause = ! options .pause
45+ }
3846 return runCommit (cmd .Context (), dockerCLI , & options )
3947 },
4048 Annotations : map [string ]string {
@@ -47,7 +55,11 @@ func newCommitCommand(dockerCLI command.Cli) *cobra.Command {
4755 flags := cmd .Flags ()
4856 flags .SetInterspersed (false )
4957
50- flags .BoolVarP (& options .pause , "pause" , "p" , true , "Pause container during commit" )
58+ // TODO(thaJeztah): Deprecated: the --pause flag was deprecated in v29 and can be removed in v30.
59+ flags .BoolVarP (& options .pause , "pause" , "p" , true , "Pause container during commit (deprecated: use --no-pause instead)" )
60+ _ = flags .MarkDeprecated ("pause" , "and enabled by default. Use --no-pause to disable pausing during commit." )
61+
62+ flags .BoolVar (& options .noPause , "no-pause" , false , "Disable pausing container during commit" )
5163 flags .StringVarP (& options .comment , "message" , "m" , "" , "Commit message" )
5264 flags .
StringVarP (
& options .
author ,
"author" ,
"a" ,
"" ,
`Author (e.g., "John Hannibal Smith <[email protected] >")` )
5365
@@ -63,12 +75,12 @@ func runCommit(ctx context.Context, dockerCli command.Cli, options *commitOption
6375 Comment : options .comment ,
6476 Author : options .author ,
6577 Changes : options .changes .GetSlice (),
66- Pause : options .pause ,
78+ Pause : ! options .noPause ,
6779 })
6880 if err != nil {
6981 return err
7082 }
7183
72- fmt .Fprintln (dockerCli .Out (), response .ID )
84+ _ , _ = fmt .Fprintln (dockerCli .Out (), response .ID )
7385 return nil
7486}
0 commit comments