Skip to content

Commit

Permalink
Move ListVar into common, so it can be reused elsewhere.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Aug 12, 2015
1 parent 1a11b98 commit 91debc2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
31 changes: 31 additions & 0 deletions common/listvar.go
@@ -0,0 +1,31 @@
package common

import (
"fmt"

"github.com/docker/docker/pkg/mflag"
)

type listOpts struct {
value *[]string
hasBeenSet bool
}

func ListVar(p *[]string, names []string, value []string, usage string) {
*p = value
mflag.Var(&listOpts{p, false}, names, usage)
}

func (opts *listOpts) Set(value string) error {
if opts.hasBeenSet {
(*opts.value) = append((*opts.value), value)
} else {
(*opts.value) = []string{value}
opts.hasBeenSet = true
}
return nil
}

func (opts *listOpts) String() string {
return fmt.Sprintf("%v", []string(*opts.value))
}
24 changes: 0 additions & 24 deletions prog/weaveproxy/main.go
Expand Up @@ -14,30 +14,6 @@ var (
version = "(unreleased version)"
)

type listOpts struct {
value *[]string
hasBeenSet bool
}

func ListVar(p *[]string, names []string, value []string, usage string) {
*p = value
mflag.Var(&listOpts{p, false}, names, usage)
}

func (opts *listOpts) Set(value string) error {
if opts.hasBeenSet {
(*opts.value) = append((*opts.value), value)
} else {
(*opts.value) = []string{value}
opts.hasBeenSet = true
}
return nil
}

func (opts *listOpts) String() string {
return fmt.Sprintf("%v", []string(*opts.value))
}

func main() {
var (
justVersion bool
Expand Down

0 comments on commit 91debc2

Please sign in to comment.