@@ -24,11 +24,15 @@ public class CommitCmd extends AbstrDockerCmd<CommitCmd, String> {
2424
2525 private static final Logger LOGGER = LoggerFactory .getLogger (CommitCmd .class );
2626
27- private CommitConfig commitConfig ;
27+ private String containerId , repository , tag , message , author ;
28+
29+ private boolean pause = true ;
30+
31+ private CommitConfig commitConfig = new CommitConfig ();
2832
2933 public CommitCmd (String containerId ) {
3034 Preconditions .checkNotNull (containerId , "containerId was not specified" );
31- this .commitConfig = new CommitConfig ( containerId ) ;
35+ this .containerId = containerId ;
3236 }
3337
3438 public CommitCmd withCommitConfig (CommitConfig commitConfig ) {
@@ -37,44 +41,81 @@ public CommitCmd withCommitConfig(CommitConfig commitConfig) {
3741 return this ;
3842 }
3943
40- public CommitCmd withRepo (String repo ) {
41- Preconditions .checkNotNull (repo , "repo was not specified" );
42- this .commitConfig .setRepo (repo );
44+ public CommitCmd withAttachStderr (boolean attachStderr ) {
45+ this .commitConfig .setAttachStderr (attachStderr );
4346 return this ;
4447 }
4548
46- public CommitCmd withTag (String tag ) {
47- Preconditions .checkNotNull (tag , "tag was not specified" );
48- this .commitConfig .setTag (tag );
49+ public CommitCmd withAttachStderr () {
50+ return withAttachStderr (true );
51+ }
52+
53+ public CommitCmd withAttachStdin (boolean attachStdin ) {
54+ this .commitConfig .setAttachStdin (attachStdin );
4955 return this ;
5056 }
57+
58+ public CommitCmd withAttachStdin () {
59+ return withAttachStdin (true );
60+ }
5161
52- public CommitCmd withMessage (String message ) {
53- Preconditions .checkNotNull (message , "message was not specified" );
54- this .commitConfig .setMessage (message );
62+ public CommitCmd withAttachStdout (boolean attachStdout ) {
63+ this .commitConfig .setAttachStdout (attachStdout );
64+ return this ;
65+ }
66+
67+ public CommitCmd withAttachStdout () {
68+ return withAttachStdout (true );
69+ }
70+
71+ public CommitCmd withCmd (String ... cmd ) {
72+ Preconditions .checkNotNull (cmd , "cmd was not specified" );
73+ this .commitConfig .setCmd (cmd );
74+ return this ;
75+ }
76+
77+ public CommitCmd withDisableNetwork (boolean disableNetwork ) {
78+ this .commitConfig .setDisableNetwork (disableNetwork );
5579 return this ;
5680 }
5781
5882 public CommitCmd withAuthor (String author ) {
5983 Preconditions .checkNotNull (author , "author was not specified" );
60- this .commitConfig .setAuthor (author );
84+ this .author = author ;
85+ return this ;
86+ }
87+
88+ public CommitCmd withMessage (String message ) {
89+ Preconditions .checkNotNull (message , "message was not specified" );
90+ this .message = message ;
91+ return this ;
92+ }
93+
94+ public CommitCmd withTag (String tag ) {
95+ Preconditions .checkNotNull (tag , "tag was not specified" );
96+ this .tag = tag ;
97+ return this ;
98+ }
99+
100+ public CommitCmd withRepository (String repository ) {
101+ Preconditions .checkNotNull (repository , "repository was not specified" );
102+ this .repository = repository ;
61103 return this ;
62104 }
63105
64- public CommitCmd withRun (String run ) {
65- Preconditions .checkNotNull (run , "run was not specified" );
66- this .commitConfig .setRun (run );
106+ public CommitCmd withPause (boolean pause ) {
107+ this .pause = pause ;
67108 return this ;
68109 }
69110
70111 @ Override
71112 public String toString () {
72113 return new StringBuilder ("commit " )
73- .append (commitConfig . getAuthor () != null ? "--author " + commitConfig . getAuthor () + " " : "" )
74- .append (commitConfig . getMessage () != null ? "--message " + commitConfig . getMessage () + " " : "" )
75- .append (commitConfig . getContainerId () )
76- .append (commitConfig . getRepo () != null ? " " + commitConfig . getRepo () + ":" : " " )
77- .append (commitConfig . getTag () != null ? commitConfig . getTag () : "" )
114+ .append (author != null ? "--author " + author + " " : "" )
115+ .append (message != null ? "--message " + message + " " : "" )
116+ .append (containerId )
117+ .append (repository != null ? " " + repository + ":" : " " )
118+ .append (tag != null ? tag : "" )
78119 .toString ();
79120 }
80121
@@ -86,12 +127,12 @@ protected String impl() throws DockerException {
86127 checkCommitConfig (commitConfig );
87128
88129 MultivaluedMap <String , String > params = new MultivaluedMapImpl ();
89- params .add ("container" , commitConfig . getContainerId () );
90- params .add ("repo" , commitConfig . getRepo () );
91- params .add ("tag" , commitConfig . getTag () );
92- params .add ("m" , commitConfig . getMessage () );
93- params .add ("author" , commitConfig . getAuthor () );
94- params .add ("run " , commitConfig . getRun () );
130+ params .add ("container" , containerId );
131+ params .add ("repo" , repository );
132+ params .add ("tag" , tag );
133+ params .add ("m" , message );
134+ params .add ("author" , author );
135+ params .add ("pause " , pause ? "1" : "0" );
95136
96137 WebResource webResource = baseResource .path ("/commit" ).queryParams (params );
97138
@@ -101,7 +142,7 @@ protected String impl() throws DockerException {
101142 return ObjectNode .get ("Id" ).asText ();
102143 } catch (UniformInterfaceException exception ) {
103144 if (exception .getResponse ().getStatus () == 404 ) {
104- throw new NotFoundException (String .format ("No such container %s" , commitConfig . getContainerId () ));
145+ throw new NotFoundException (String .format ("No such container %s" , containerId ));
105146 } else if (exception .getResponse ().getStatus () == 500 ) {
106147 throw new DockerException ("Server error" , exception );
107148 } else {
0 commit comments