Remove useless New*Opt functions, singleline Opt types

This commit is contained in:
Guillaume J. Charmes 2013-11-22 14:42:30 -08:00
parent 1c8ae47770
commit c67f9b671d
No known key found for this signature in database
GPG Key ID: B33E4642CB6E3FF3
2 changed files with 11 additions and 34 deletions

View File

@ -241,7 +241,7 @@ func (b *buildFile) CmdVolume(args string) error {
volume = []string{args} volume = []string{args}
} }
if b.config.Volumes == nil { if b.config.Volumes == nil {
b.config.Volumes = NewPathOpts() b.config.Volumes = PathOpts{}
} }
for _, v := range volume { for _, v := range volume {
b.config.Volumes[v] = struct{}{} b.config.Volumes[v] = struct{}{}

View File

@ -1632,15 +1632,7 @@ type ports []int
// AttachOpts stores arguments to 'docker run -a', eg. which streams to attach to // AttachOpts stores arguments to 'docker run -a', eg. which streams to attach to
type AttachOpts map[string]bool type AttachOpts map[string]bool
func NewAttachOpts() AttachOpts { func (opts AttachOpts) String() string { return fmt.Sprintf("%v", map[string]bool(opts)) }
return make(AttachOpts)
}
func (opts AttachOpts) String() string {
// Cast to underlying map type to avoid infinite recursion
return fmt.Sprintf("%v", map[string]bool(opts))
}
func (opts AttachOpts) Set(val string) error { func (opts AttachOpts) Set(val string) error {
if val != "stdin" && val != "stdout" && val != "stderr" { if val != "stdin" && val != "stdout" && val != "stderr" {
return fmt.Errorf("Unsupported stream name: %s", val) return fmt.Errorf("Unsupported stream name: %s", val)
@ -1649,18 +1641,10 @@ func (opts AttachOpts) Set(val string) error {
return nil return nil
} }
func (opts AttachOpts) Get(val string) bool { // LinkOpts stores arguments to `docker run -link`
if res, exists := opts[val]; exists {
return res
}
return false
}
type LinkOpts []string type LinkOpts []string
func (link LinkOpts) String() string { func (link LinkOpts) String() string { return fmt.Sprintf("%v", []string(link)) }
return fmt.Sprintf("%v", []string(link))
}
func (link LinkOpts) Set(val string) error { func (link LinkOpts) Set(val string) error {
if _, err := parseLink(val); err != nil { if _, err := parseLink(val); err != nil {
return err return err
@ -1671,14 +1655,7 @@ func (link LinkOpts) Set(val string) error {
// PathOpts stores a unique set of absolute paths // PathOpts stores a unique set of absolute paths
type PathOpts map[string]struct{} type PathOpts map[string]struct{}
func NewPathOpts() PathOpts { func (opts PathOpts) String() string { return fmt.Sprintf("%v", map[string]struct{}(opts)) }
return make(PathOpts)
}
func (opts PathOpts) String() string {
return fmt.Sprintf("%v", map[string]struct{}(opts))
}
func (opts PathOpts) Set(val string) error { func (opts PathOpts) Set(val string) error {
var containerPath string var containerPath string
@ -1744,8 +1721,8 @@ func ParseRun(args []string, capabilities *Capabilities) (*Config, *HostConfig,
func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Config, *HostConfig, *flag.FlagSet, error) { func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Config, *HostConfig, *flag.FlagSet, error) {
var ( var (
// FIXME: use utils.ListOpts for attach and volumes? // FIXME: use utils.ListOpts for attach and volumes?
flAttach = NewAttachOpts() flAttach = AttachOpts{}
flVolumes = NewPathOpts() flVolumes = PathOpts{}
flLinks = LinkOpts{} flLinks = LinkOpts{}
flPublish utils.ListOpts flPublish utils.ListOpts
@ -1777,6 +1754,7 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co
cmd.Var(flAttach, "a", "Attach to stdin, stdout or stderr.") cmd.Var(flAttach, "a", "Attach to stdin, stdout or stderr.")
cmd.Var(flVolumes, "v", "Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)") cmd.Var(flVolumes, "v", "Bind mount a volume (e.g. from the host: -v /host:/container, from docker: -v /container)")
cmd.Var(flLinks, "link", "Add link to another container (name:alias)")
cmd.Var(&flPublish, "p", fmt.Sprintf("Publish a container's port to the host (format: %s) (use 'docker port' to see the actual mapping)", PortSpecTemplateFormat)) cmd.Var(&flPublish, "p", fmt.Sprintf("Publish a container's port to the host (format: %s) (use 'docker port' to see the actual mapping)", PortSpecTemplateFormat))
cmd.Var(&flExpose, "expose", "Expose a port from the container without publishing it to your host") cmd.Var(&flExpose, "expose", "Expose a port from the container without publishing it to your host")
@ -1784,7 +1762,6 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co
cmd.Var(&flDns, "dns", "Set custom dns servers") cmd.Var(&flDns, "dns", "Set custom dns servers")
cmd.Var(&flVolumesFrom, "volumes-from", "Mount volumes from the specified container(s)") cmd.Var(&flVolumesFrom, "volumes-from", "Mount volumes from the specified container(s)")
cmd.Var(&flLxcOpts, "lxc-conf", "Add custom lxc options -lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"") cmd.Var(&flLxcOpts, "lxc-conf", "Add custom lxc options -lxc-conf=\"lxc.cgroup.cpuset.cpus = 0,1\"")
cmd.Var(&flLinks, "link", "Add link to another container (name:alias)")
if err := cmd.Parse(args); err != nil { if err := cmd.Parse(args); err != nil {
return nil, nil, cmd, err return nil, nil, cmd, err
@ -1910,9 +1887,9 @@ func parseRun(cmd *flag.FlagSet, args []string, capabilities *Capabilities) (*Co
OpenStdin: *flStdin, OpenStdin: *flStdin,
Memory: flMemory, Memory: flMemory,
CpuShares: *flCpuShares, CpuShares: *flCpuShares,
AttachStdin: flAttach.Get("stdin"), AttachStdin: flAttach["stdin"],
AttachStdout: flAttach.Get("stdout"), AttachStdout: flAttach["stdout"],
AttachStderr: flAttach.Get("stderr"), AttachStderr: flAttach["stderr"],
Env: envs, Env: envs,
Cmd: runCmd, Cmd: runCmd,
Dns: flDns, Dns: flDns,