mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
clean up AttachOpts type
Primarily, there is no reason to have a pointer to a map. Furthermore, make() can be used on AttachOpts directly.
This commit is contained in:
parent
15c3096e89
commit
4f36039e7b
2 changed files with 11 additions and 11 deletions
18
commands.go
18
commands.go
|
@ -833,25 +833,25 @@ func (opts *ListOpts) Set(value string) error {
|
||||||
// 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 NewAttachOpts() AttachOpts {
|
||||||
opts := make(map[string]bool)
|
return make(AttachOpts)
|
||||||
return (*AttachOpts)(&opts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *AttachOpts) String() string {
|
func (opts AttachOpts) String() string {
|
||||||
return fmt.Sprint(*opts)
|
// 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)
|
||||||
}
|
}
|
||||||
(*opts)[val] = true
|
opts[val] = true
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opts *AttachOpts) Get(val string) bool {
|
func (opts AttachOpts) Get(val string) bool {
|
||||||
if res, exists := (*opts)[val]; exists {
|
if res, exists := opts[val]; exists {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -88,11 +88,11 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
|
||||||
if err := cmd.Parse(args); err != nil {
|
if err := cmd.Parse(args); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if *flDetach && len(*flAttach) > 0 {
|
if *flDetach && len(flAttach) > 0 {
|
||||||
return nil, fmt.Errorf("Conflicting options: -a and -d")
|
return nil, fmt.Errorf("Conflicting options: -a and -d")
|
||||||
}
|
}
|
||||||
// If neither -d or -a are set, attach to everything by default
|
// If neither -d or -a are set, attach to everything by default
|
||||||
if len(*flAttach) == 0 && !*flDetach {
|
if len(flAttach) == 0 && !*flDetach {
|
||||||
if !*flDetach {
|
if !*flDetach {
|
||||||
flAttach.Set("stdout")
|
flAttach.Set("stdout")
|
||||||
flAttach.Set("stderr")
|
flAttach.Set("stderr")
|
||||||
|
|
Loading…
Add table
Reference in a new issue