Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Move ListVar into common, so it can be reused elsewhere. #1289

Merged
merged 1 commit into from
Aug 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions common/mflagext/listvar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package mflagext

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))
}
27 changes: 2 additions & 25 deletions prog/weaveproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,14 @@ import (

"github.com/docker/docker/pkg/mflag"
. "github.com/weaveworks/weave/common"
"github.com/weaveworks/weave/common/mflagext"
"github.com/weaveworks/weave/proxy"
)

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 All @@ -49,7 +26,7 @@ func main() {

mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
mflag.StringVar(&logLevel, []string{"-log-level"}, "info", "logging level (debug, info, warning, error)")
ListVar(&c.ListenAddrs, []string{"H"}, nil, "addresses on which to listen")
mflagext.ListVar(&c.ListenAddrs, []string{"H"}, nil, "addresses on which to listen")
mflag.StringVar(&c.HostnameMatch, []string{"-hostname-match"}, "(.*)", "Regexp pattern to apply on container names (e.g. '^aws-[0-9]+-(.*)$')")
mflag.StringVar(&c.HostnameReplacement, []string{"-hostname-replacement"}, "$1", "Expression to generate hostnames based on matches from --hostname-match (e.g. 'my-app-$1')")
mflag.BoolVar(&c.NoDefaultIPAM, []string{"#-no-default-ipam", "-no-default-ipalloc"}, false, "do not automatically allocate addresses for containers without a WEAVE_CIDR")
Expand Down