cli: new daemon command and new cli package

This patch creates a new cli package that allows to combine both client
and daemon commands (there is only one daemon command: docker daemon).

The `-d` and `--daemon` top-level flags are deprecated and a special
message is added to prompt the user to use `docker daemon`.

Providing top-level daemon-specific flags for client commands result
in an error message prompting the user to use `docker daemon`.

This patch does not break any old but correct usages.

This also makes `-d` and `--daemon` flags, as well as the `daemon`
command illegal in client-only binaries.

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2015-05-05 00:18:28 -04:00 коммит произвёл Vincent Demeester
Родитель 7b9ceadc4d
Коммит f55d8241cf
5 изменённых файлов: 37 добавлений и 17 удалений

7
opts/hosts_unix.go Normal file
Просмотреть файл

@ -0,0 +1,7 @@
// +build !windows
package opts
import "fmt"
var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket)

7
opts/hosts_windows.go Normal file
Просмотреть файл

@ -0,0 +1,7 @@
// +build windows
package opts
import "fmt"
var DefaultHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort)

Просмотреть файл

@ -32,37 +32,37 @@ var (
// ListVar Defines a flag with the specified names and usage, and put the value
// list into ListOpts that will hold the values.
func ListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, nil), names, usage)
flag.Var(NewListOptsRef(values, nil), names, usage)
}
// MapVar Defines a flag with the specified names and usage, and put the value
// map into MapOpt that will hold the values (key,value).
func MapVar(values map[string]string, names []string, usage string) {
flag.Var(newMapOpt(values, nil), names, usage)
flag.Var(NewMapOpts(values, nil), names, usage)
}
// LogOptsVar Defines a flag with the specified names and usage for --log-opts,
// and put the value map into MapOpt that will hold the values (key,value).
func LogOptsVar(values map[string]string, names []string, usage string) {
flag.Var(newMapOpt(values, nil), names, usage)
flag.Var(NewMapOpts(values, nil), names, usage)
}
// HostListVar Defines a flag with the specified names and usage and put the
// value into a ListOpts that will hold the values, validating the Host format.
func HostListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateHost), names, usage)
flag.Var(NewListOptsRef(values, ValidateHost), names, usage)
}
// IPListVar Defines a flag with the specified names and usage and put the
// value into a ListOpts that will hold the values, validating the IP format.
func IPListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateIPAddress), names, usage)
flag.Var(NewListOptsRef(values, ValidateIPAddress), names, usage)
}
// DNSSearchListVar Defines a flag with the specified names and usage and put the
// value into a ListOpts that will hold the values, validating the DNS search format.
func DNSSearchListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateDNSSearch), names, usage)
flag.Var(NewListOptsRef(values, ValidateDNSSearch), names, usage)
}
// IPVar Defines a flag with the specified names and usage for IP and will use
@ -74,12 +74,12 @@ func IPVar(value *net.IP, names []string, defaultValue, usage string) {
// LabelListVar Defines a flag with the specified names and usage and put the
// value into a ListOpts that will hold the values, validating the label format.
func LabelListVar(values *[]string, names []string, usage string) {
flag.Var(newListOptsRef(values, ValidateLabel), names, usage)
flag.Var(NewListOptsRef(values, ValidateLabel), names, usage)
}
// UlimitMapVar Defines a flag with the specified names and usage for --ulimit,
// and put the value map into a UlimitOpt that will hold the values.
func UlimitMapVar(values map[string]*ulimit.Ulimit, names []string, usage string) {
func UlimitMapVar(values *map[string]*ulimit.Ulimit, names []string, usage string) {
flag.Var(NewUlimitOpt(values), names, usage)
}
@ -92,10 +92,10 @@ type ListOpts struct {
// NewListOpts Create a new ListOpts with the specified validator.
func NewListOpts(validator ValidatorFctType) ListOpts {
var values []string
return *newListOptsRef(&values, validator)
return *NewListOptsRef(&values, validator)
}
func newListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts {
return &ListOpts{
values: values,
validator: validator,
@ -191,7 +191,10 @@ func (opts *MapOpts) String() string {
return fmt.Sprintf("%v", map[string]string((opts.values)))
}
func newMapOpt(values map[string]string, validator ValidatorFctType) *MapOpts {
func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts {
if values == nil {
values = make(map[string]string)
}
return &MapOpts{
values: values,
validator: validator,

Просмотреть файл

@ -32,7 +32,7 @@ func TestValidateIPAddress(t *testing.T) {
func TestMapOpts(t *testing.T) {
tmpMap := make(map[string]string)
o := newMapOpt(tmpMap, logOptsValidator)
o := NewMapOpts(tmpMap, logOptsValidator)
o.Set("max-size=1")
if o.String() != "map[max-size:1]" {
t.Errorf("%s != [map[max-size:1]", o.String())

Просмотреть файл

@ -7,10 +7,13 @@ import (
)
type UlimitOpt struct {
values map[string]*ulimit.Ulimit
values *map[string]*ulimit.Ulimit
}
func NewUlimitOpt(ref map[string]*ulimit.Ulimit) *UlimitOpt {
func NewUlimitOpt(ref *map[string]*ulimit.Ulimit) *UlimitOpt {
if ref == nil {
ref = &map[string]*ulimit.Ulimit{}
}
return &UlimitOpt{ref}
}
@ -20,14 +23,14 @@ func (o *UlimitOpt) Set(val string) error {
return err
}
o.values[l.Name] = l
(*o.values)[l.Name] = l
return nil
}
func (o *UlimitOpt) String() string {
var out []string
for _, v := range o.values {
for _, v := range *o.values {
out = append(out, v.String())
}
@ -36,7 +39,7 @@ func (o *UlimitOpt) String() string {
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
var ulimits []*ulimit.Ulimit
for _, v := range o.values {
for _, v := range *o.values {
ulimits = append(ulimits, v)
}