Browse code

Make the commit configuration to be a typed struct rather than accepting a string.

Signed-off-by: David Calavera <david.calavera@gmail.com>

David Calavera authored on 2015/12/10 02:03:09
Showing 3 changed files
... ...
@@ -1,6 +1,7 @@
1 1
 package client
2 2
 
3 3
 import (
4
+	"encoding/json"
4 5
 	"errors"
5 6
 	"fmt"
6 7
 
... ...
@@ -10,6 +11,7 @@ import (
10 10
 	"github.com/docker/docker/opts"
11 11
 	flag "github.com/docker/docker/pkg/mflag"
12 12
 	"github.com/docker/docker/registry"
13
+	"github.com/docker/docker/runconfig"
13 14
 )
14 15
 
15 16
 // CmdCommit creates a new image from a container's changes.
... ...
@@ -56,6 +58,14 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
56 56
 		}
57 57
 	}
58 58
 
59
+	var config *runconfig.Config
60
+	if *flConfig != "" {
61
+		config = &runconfig.Config{}
62
+		if err := json.Unmarshal([]byte(*flConfig), config); err != nil {
63
+			return err
64
+		}
65
+	}
66
+
59 67
 	options := types.ContainerCommitOptions{
60 68
 		ContainerID:    name,
61 69
 		RepositoryName: repositoryName,
... ...
@@ -64,7 +74,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
64 64
 		Author:         *flAuthor,
65 65
 		Changes:        flChanges.GetAll(),
66 66
 		Pause:          *flPause,
67
-		JSONConfig:     *flConfig,
67
+		Config:         config,
68 68
 	}
69 69
 
70 70
 	response, err := cli.client.ContainerCommit(options)
... ...
@@ -5,7 +5,6 @@ import (
5 5
 	"net/url"
6 6
 
7 7
 	"github.com/docker/docker/api/types"
8
-	"github.com/docker/docker/runconfig"
9 8
 )
10 9
 
11 10
 // ContainerCommit applies changes into a container and creates a new tagged image.
... ...
@@ -23,19 +22,8 @@ func (cli *Client) ContainerCommit(options types.ContainerCommitOptions) (types.
23 23
 		query.Set("pause", "0")
24 24
 	}
25 25
 
26
-	var (
27
-		config   *runconfig.Config
28
-		response types.ContainerCommitResponse
29
-	)
30
-
31
-	if options.JSONConfig != "" {
32
-		config = &runconfig.Config{}
33
-		if err := json.Unmarshal([]byte(options.JSONConfig), config); err != nil {
34
-			return response, err
35
-		}
36
-	}
37
-
38
-	resp, err := cli.post("/commit", query, config, nil)
26
+	var response types.ContainerCommitResponse
27
+	resp, err := cli.post("/commit", query, options.Config, nil)
39 28
 	if err != nil {
40 29
 		return response, err
41 30
 	}
... ...
@@ -8,6 +8,7 @@ import (
8 8
 	"github.com/docker/docker/cliconfig"
9 9
 	"github.com/docker/docker/pkg/parsers/filters"
10 10
 	"github.com/docker/docker/pkg/ulimit"
11
+	"github.com/docker/docker/runconfig"
11 12
 )
12 13
 
13 14
 // ContainerAttachOptions holds parameters to attach to a container.
... ...
@@ -28,7 +29,7 @@ type ContainerCommitOptions struct {
28 28
 	Author         string
29 29
 	Changes        []string
30 30
 	Pause          bool
31
-	JSONConfig     string
31
+	Config         *runconfig.Config
32 32
 }
33 33
 
34 34
 // ContainerExecInspect holds information returned by exec inspect.