Browse code

Move ListOps to utils submodule

This will be needed for later use in docker-init without a docker
dependency

Alexander Larsson authored on 2013/10/10 17:49:18
Showing 6 changed files
... ...
@@ -1480,18 +1480,6 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
1480 1480
 // Ports type - Used to parse multiple -p flags
1481 1481
 type ports []int
1482 1482
 
1483
-// ListOpts type
1484
-type ListOpts []string
1485
-
1486
-func (opts *ListOpts) String() string {
1487
-	return fmt.Sprint(*opts)
1488
-}
1489
-
1490
-func (opts *ListOpts) Set(value string) error {
1491
-	*opts = append(*opts, value)
1492
-	return nil
1493
-}
1494
-
1495 1483
 // AttachOpts stores arguments to 'docker run -a', eg. which streams to attach to
1496 1484
 type AttachOpts map[string]bool
1497 1485
 
... ...
@@ -175,30 +175,30 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
175 175
 
176 176
 	flCpuShares := cmd.Int64("c", 0, "CPU shares (relative weight)")
177 177
 
178
-	var flPublish ListOpts
178
+	var flPublish utils.ListOpts
179 179
 	cmd.Var(&flPublish, "p", "Publish a container's port to the host (use 'docker port' to see the actual mapping)")
180 180
 
181
-	var flExpose ListOpts
181
+	var flExpose utils.ListOpts
182 182
 	cmd.Var(&flExpose, "expose", "Expose a port from the container without publishing it to your host")
183 183
 
184
-	var flEnv ListOpts
184
+	var flEnv utils.ListOpts
185 185
 	cmd.Var(&flEnv, "e", "Set environment variables")
186 186
 
187
-	var flDns ListOpts
187
+	var flDns utils.ListOpts
188 188
 	cmd.Var(&flDns, "dns", "Set custom dns servers")
189 189
 
190 190
 	flVolumes := NewPathOpts()
191 191
 	cmd.Var(flVolumes, "v", "Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)")
192 192
 
193
-	var flVolumesFrom ListOpts
193
+	var flVolumesFrom utils.ListOpts
194 194
 	cmd.Var(&flVolumesFrom, "volumes-from", "Mount volumes from the specified container")
195 195
 
196 196
 	flEntrypoint := cmd.String("entrypoint", "", "Overwrite the default entrypoint of the image")
197 197
 
198
-	var flLxcOpts ListOpts
198
+	var flLxcOpts utils.ListOpts
199 199
 	cmd.Var(&flLxcOpts, "lxc-conf", "Add custom lxc options -lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
200 200
 
201
-	var flLinks ListOpts
201
+	var flLinks utils.ListOpts
202 202
 	cmd.Var(&flLinks, "link", "Add link to another container (containerid:alias)")
203 203
 
204 204
 	if err := cmd.Parse(args); err != nil {
... ...
@@ -36,7 +36,7 @@ func main() {
36 36
 	flGraphPath := flag.String("g", "/var/lib/docker", "Path to graph storage base dir.")
37 37
 	flEnableCors := flag.Bool("api-enable-cors", false, "Enable CORS requests in the remote api.")
38 38
 	flDns := flag.String("dns", "", "Set custom dns servers")
39
-	flHosts := docker.ListOpts{fmt.Sprintf("unix://%s", docker.DEFAULTUNIXSOCKET)}
39
+	flHosts := utils.ListOpts{fmt.Sprintf("unix://%s", docker.DEFAULTUNIXSOCKET)}
40 40
 	flag.Var(&flHosts, "H", "tcp://host:port to bind/connect to or unix://path/to/socket to use")
41 41
 	flEnableIptables := flag.Bool("iptables", true, "Disable iptables within docker")
42 42
 	flDefaultIp := flag.String("ip", "0.0.0.0", "Default ip address to use when binding a containers ports")
... ...
@@ -69,7 +69,7 @@ func changeUser(u string) {
69 69
 }
70 70
 
71 71
 // Clear environment pollution introduced by lxc-start
72
-func cleanupEnv(env ListOpts) {
72
+func cleanupEnv(env utils.ListOpts) {
73 73
 	os.Clearenv()
74 74
 	for _, kv := range env {
75 75
 		parts := strings.SplitN(kv, "=", 2)
... ...
@@ -104,7 +104,7 @@ func SysInit() {
104 104
 	var gw = flag.String("g", "", "gateway address")
105 105
 	var workdir = flag.String("w", "", "workdir")
106 106
 
107
-	var flEnv ListOpts
107
+	var flEnv utils.ListOpts
108 108
 	flag.Var(&flEnv, "e", "Set environment variables")
109 109
 
110 110
 	flag.Parse()
... ...
@@ -175,7 +175,7 @@ func MergeConfig(userConf, imageConf *Config) error {
175 175
 	return nil
176 176
 }
177 177
 
178
-func parseLxcConfOpts(opts ListOpts) ([]KeyValuePair, error) {
178
+func parseLxcConfOpts(opts utils.ListOpts) ([]KeyValuePair, error) {
179 179
 	out := make([]KeyValuePair, len(opts))
180 180
 	for i, o := range opts {
181 181
 		k, v, err := parseLxcOpt(o)
... ...
@@ -21,6 +21,18 @@ import (
21 21
 	"time"
22 22
 )
23 23
 
24
+// ListOpts type
25
+type ListOpts []string
26
+
27
+func (opts *ListOpts) String() string {
28
+	return fmt.Sprint(*opts)
29
+}
30
+
31
+func (opts *ListOpts) Set(value string) error {
32
+	*opts = append(*opts, value)
33
+	return nil
34
+}
35
+
24 36
 // Go is a basic promise implementation: it wraps calls a function in a goroutine,
25 37
 // and returns a channel which will later return the function's return value.
26 38
 func Go(f func() error) chan error {