mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
pkg/opts: a collection of custom value parsers implementing flag.Value
This facilitates the refactoring of commands.go. Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
e08a1c53aa
commit
e6e320acc7
5 changed files with 28 additions and 14 deletions
19
commands.go
19
commands.go
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
"github.com/dotcloud/docker/nat"
|
"github.com/dotcloud/docker/nat"
|
||||||
flag "github.com/dotcloud/docker/pkg/mflag"
|
flag "github.com/dotcloud/docker/pkg/mflag"
|
||||||
|
"github.com/dotcloud/docker/pkg/opts"
|
||||||
"github.com/dotcloud/docker/pkg/sysinfo"
|
"github.com/dotcloud/docker/pkg/sysinfo"
|
||||||
"github.com/dotcloud/docker/pkg/term"
|
"github.com/dotcloud/docker/pkg/term"
|
||||||
"github.com/dotcloud/docker/registry"
|
"github.com/dotcloud/docker/registry"
|
||||||
|
@ -1757,16 +1758,16 @@ func ParseRun(args []string, sysInfo *sysinfo.SysInfo) (*Config, *HostConfig, *f
|
||||||
func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, *HostConfig, *flag.FlagSet, error) {
|
func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Config, *HostConfig, *flag.FlagSet, error) {
|
||||||
var (
|
var (
|
||||||
// FIXME: use utils.ListOpts for attach and volumes?
|
// FIXME: use utils.ListOpts for attach and volumes?
|
||||||
flAttach = NewListOpts(ValidateAttach)
|
flAttach = opts.NewListOpts(opts.ValidateAttach)
|
||||||
flVolumes = NewListOpts(ValidatePath)
|
flVolumes = opts.NewListOpts(opts.ValidatePath)
|
||||||
flLinks = NewListOpts(ValidateLink)
|
flLinks = opts.NewListOpts(opts.ValidateLink)
|
||||||
flEnv = NewListOpts(ValidateEnv)
|
flEnv = opts.NewListOpts(opts.ValidateEnv)
|
||||||
|
|
||||||
flPublish ListOpts
|
flPublish opts.ListOpts
|
||||||
flExpose ListOpts
|
flExpose opts.ListOpts
|
||||||
flDns ListOpts
|
flDns opts.ListOpts
|
||||||
flVolumesFrom ListOpts
|
flVolumesFrom opts.ListOpts
|
||||||
flLxcOpts ListOpts
|
flLxcOpts opts.ListOpts
|
||||||
|
|
||||||
flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
|
flAutoRemove = cmd.Bool([]string{"#rm", "-rm"}, false, "Automatically remove the container when it exits (incompatible with -d)")
|
||||||
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
|
flDetach = cmd.Bool([]string{"d", "-detach"}, false, "Detached mode: Run container in the background, print new container id")
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/dotcloud/docker/api"
|
"github.com/dotcloud/docker/api"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
flag "github.com/dotcloud/docker/pkg/mflag"
|
flag "github.com/dotcloud/docker/pkg/mflag"
|
||||||
|
"github.com/dotcloud/docker/pkg/opts"
|
||||||
"github.com/dotcloud/docker/sysinit"
|
"github.com/dotcloud/docker/sysinit"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
)
|
)
|
||||||
|
@ -36,13 +37,13 @@ func main() {
|
||||||
pidfile = flag.String([]string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
|
pidfile = flag.String([]string{"p", "-pidfile"}, "/var/run/docker.pid", "Path to use for daemon PID file")
|
||||||
flRoot = flag.String([]string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the docker runtime")
|
flRoot = flag.String([]string{"g", "-graph"}, "/var/lib/docker", "Path to use as the root of the docker runtime")
|
||||||
flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
|
flEnableCors = flag.Bool([]string{"#api-enable-cors", "-api-enable-cors"}, false, "Enable CORS headers in the remote API")
|
||||||
flDns = docker.NewListOpts(docker.ValidateIp4Address)
|
flDns = opts.NewListOpts(opts.ValidateIp4Address)
|
||||||
flEnableIptables = flag.Bool([]string{"#iptables", "-iptables"}, true, "Disable docker's addition of iptables rules")
|
flEnableIptables = flag.Bool([]string{"#iptables", "-iptables"}, true, "Disable docker's addition of iptables rules")
|
||||||
flEnableIpForward = flag.Bool([]string{"#ip-forward", "-ip-forward"}, true, "Disable enabling of net.ipv4.ip_forward")
|
flEnableIpForward = flag.Bool([]string{"#ip-forward", "-ip-forward"}, true, "Disable enabling of net.ipv4.ip_forward")
|
||||||
flDefaultIp = flag.String([]string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
|
flDefaultIp = flag.String([]string{"#ip", "-ip"}, "0.0.0.0", "Default IP address to use when binding container ports")
|
||||||
flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
||||||
flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver")
|
flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver")
|
||||||
flHosts = docker.NewListOpts(api.ValidateHost)
|
flHosts = opts.NewListOpts(api.ValidateHost)
|
||||||
flMtu = flag.Int([]string{"#mtu", "-mtu"}, 0, "Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if not default route is available")
|
flMtu = flag.Int([]string{"#mtu", "-mtu"}, 0, "Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if not default route is available")
|
||||||
)
|
)
|
||||||
flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers")
|
flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers")
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package docker
|
package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/dotcloud/docker/utils"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -97,6 +98,16 @@ func ValidateLink(val string) (string, error) {
|
||||||
return val, nil
|
return val, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: this is a duplicate of docker.utils.parseLink.
|
||||||
|
// it can't be moved to a separate links/ package because
|
||||||
|
// links depends on Container which is defined in the core.
|
||||||
|
//
|
||||||
|
// Links come in the format of
|
||||||
|
// name:alias
|
||||||
|
func parseLink(rawLink string) (map[string]string, error) {
|
||||||
|
return utils.PartParser("name:alias", rawLink)
|
||||||
|
}
|
||||||
|
|
||||||
func ValidatePath(val string) (string, error) {
|
func ValidatePath(val string) (string, error) {
|
||||||
var containerPath string
|
var containerPath string
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package docker
|
package opts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
3
utils.go
3
utils.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/dotcloud/docker/archive"
|
"github.com/dotcloud/docker/archive"
|
||||||
"github.com/dotcloud/docker/nat"
|
"github.com/dotcloud/docker/nat"
|
||||||
"github.com/dotcloud/docker/pkg/namesgenerator"
|
"github.com/dotcloud/docker/pkg/namesgenerator"
|
||||||
|
"github.com/dotcloud/docker/pkg/opts"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -192,7 +193,7 @@ func MergeConfig(userConf, imageConf *Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseLxcConfOpts(opts ListOpts) ([]KeyValuePair, error) {
|
func parseLxcConfOpts(opts opts.ListOpts) ([]KeyValuePair, error) {
|
||||||
out := make([]KeyValuePair, opts.Len())
|
out := make([]KeyValuePair, opts.Len())
|
||||||
for i, o := range opts.GetAll() {
|
for i, o := range opts.GetAll() {
|
||||||
k, v, err := parseLxcOpt(o)
|
k, v, err := parseLxcOpt(o)
|
||||||
|
|
Loading…
Add table
Reference in a new issue