1
0
Fork 0
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:
Dominik Honnef 2013-04-03 16:06:35 +02:00
parent 15c3096e89
commit 4f36039e7b
2 changed files with 11 additions and 11 deletions

View file

@ -833,25 +833,25 @@ func (opts *ListOpts) Set(value string) error {
// AttachOpts stores arguments to 'docker run -a', eg. which streams to attach to
type AttachOpts map[string]bool
func NewAttachOpts() *AttachOpts {
opts := make(map[string]bool)
return (*AttachOpts)(&opts)
func NewAttachOpts() AttachOpts {
return make(AttachOpts)
}
func (opts *AttachOpts) String() string {
return fmt.Sprint(*opts)
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" {
return fmt.Errorf("Unsupported stream name: %s", val)
}
(*opts)[val] = true
opts[val] = true
return nil
}
func (opts *AttachOpts) Get(val string) bool {
if res, exists := (*opts)[val]; exists {
func (opts AttachOpts) Get(val string) bool {
if res, exists := opts[val]; exists {
return res
}
return false

View file

@ -88,11 +88,11 @@ func ParseRun(args []string, stdout io.Writer) (*Config, error) {
if err := cmd.Parse(args); err != nil {
return nil, err
}
if *flDetach && len(*flAttach) > 0 {
if *flDetach && len(flAttach) > 0 {
return nil, fmt.Errorf("Conflicting options: -a and -d")
}
// If neither -d or -a are set, attach to everything by default
if len(*flAttach) == 0 && !*flDetach {
if len(flAttach) == 0 && !*flDetach {
if !*flDetach {
flAttach.Set("stdout")
flAttach.Set("stderr")