mirror of https://github.com/docker/cli.git
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:
parent
7b9ceadc4d
commit
f55d8241cf
|
@ -0,0 +1,7 @@
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var DefaultHost = fmt.Sprintf("unix://%s", DefaultUnixSocket)
|
|
@ -0,0 +1,7 @@
|
||||||
|
// +build windows
|
||||||
|
|
||||||
|
package opts
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
var DefaultHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort)
|
25
opts/opts.go
25
opts/opts.go
|
@ -32,37 +32,37 @@ var (
|
||||||
// ListVar Defines a flag with the specified names and usage, and put the value
|
// ListVar Defines a flag with the specified names and usage, and put the value
|
||||||
// list into ListOpts that will hold the values.
|
// list into ListOpts that will hold the values.
|
||||||
func ListVar(values *[]string, names []string, usage string) {
|
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
|
// MapVar Defines a flag with the specified names and usage, and put the value
|
||||||
// map into MapOpt that will hold the values (key,value).
|
// map into MapOpt that will hold the values (key,value).
|
||||||
func MapVar(values map[string]string, names []string, usage string) {
|
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,
|
// 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).
|
// and put the value map into MapOpt that will hold the values (key,value).
|
||||||
func LogOptsVar(values map[string]string, names []string, usage string) {
|
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
|
// 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.
|
// value into a ListOpts that will hold the values, validating the Host format.
|
||||||
func HostListVar(values *[]string, names []string, usage string) {
|
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
|
// 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.
|
// value into a ListOpts that will hold the values, validating the IP format.
|
||||||
func IPListVar(values *[]string, names []string, usage string) {
|
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
|
// 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.
|
// value into a ListOpts that will hold the values, validating the DNS search format.
|
||||||
func DNSSearchListVar(values *[]string, names []string, usage string) {
|
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
|
// 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
|
// 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.
|
// value into a ListOpts that will hold the values, validating the label format.
|
||||||
func LabelListVar(values *[]string, names []string, usage string) {
|
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,
|
// 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.
|
// 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)
|
flag.Var(NewUlimitOpt(values), names, usage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,10 +92,10 @@ type ListOpts struct {
|
||||||
// NewListOpts Create a new ListOpts with the specified validator.
|
// NewListOpts Create a new ListOpts with the specified validator.
|
||||||
func NewListOpts(validator ValidatorFctType) ListOpts {
|
func NewListOpts(validator ValidatorFctType) ListOpts {
|
||||||
var values []string
|
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{
|
return &ListOpts{
|
||||||
values: values,
|
values: values,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
|
@ -191,7 +191,10 @@ func (opts *MapOpts) String() string {
|
||||||
return fmt.Sprintf("%v", map[string]string((opts.values)))
|
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{
|
return &MapOpts{
|
||||||
values: values,
|
values: values,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestValidateIPAddress(t *testing.T) {
|
||||||
|
|
||||||
func TestMapOpts(t *testing.T) {
|
func TestMapOpts(t *testing.T) {
|
||||||
tmpMap := make(map[string]string)
|
tmpMap := make(map[string]string)
|
||||||
o := newMapOpt(tmpMap, logOptsValidator)
|
o := NewMapOpts(tmpMap, logOptsValidator)
|
||||||
o.Set("max-size=1")
|
o.Set("max-size=1")
|
||||||
if o.String() != "map[max-size:1]" {
|
if o.String() != "map[max-size:1]" {
|
||||||
t.Errorf("%s != [map[max-size:1]", o.String())
|
t.Errorf("%s != [map[max-size:1]", o.String())
|
||||||
|
|
|
@ -7,10 +7,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type UlimitOpt struct {
|
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}
|
return &UlimitOpt{ref}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,14 +23,14 @@ func (o *UlimitOpt) Set(val string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
o.values[l.Name] = l
|
(*o.values)[l.Name] = l
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *UlimitOpt) String() string {
|
func (o *UlimitOpt) String() string {
|
||||||
var out []string
|
var out []string
|
||||||
for _, v := range o.values {
|
for _, v := range *o.values {
|
||||||
out = append(out, v.String())
|
out = append(out, v.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +39,7 @@ func (o *UlimitOpt) String() string {
|
||||||
|
|
||||||
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
|
func (o *UlimitOpt) GetList() []*ulimit.Ulimit {
|
||||||
var ulimits []*ulimit.Ulimit
|
var ulimits []*ulimit.Ulimit
|
||||||
for _, v := range o.values {
|
for _, v := range *o.values {
|
||||||
ulimits = append(ulimits, v)
|
ulimits = append(ulimits, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue