本文整理汇总了Golang中github.com/docker/docker/pkg/mflag.Parse函数的典型用法代码示例。如果您正苦于以下问题:Golang Parse函数的具体用法?Golang Parse怎么用?Golang Parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
ignoreIfaceNames := make(stringList)
mflag.Var(&ignoreIfaceNames, []string{"-ignore-iface"}, "name of interface to ignore)")
mflag.Parse()
if len(mflag.Args()) < 1 {
fmt.Fprintln(os.Stderr, "usage: netcheck [--ignore-iface <iface-name>] network-cidr")
os.Exit(1)
}
cidrStr := mflag.Args()[0]
addr, ipnet, err := net.ParseCIDR(cidrStr)
if err != nil {
fatal(err)
}
if ipnet.IP.Equal(addr) {
err = weavenet.CheckNetworkFree(ipnet, ignoreIfaceNames)
} else {
err = weavenet.CheckAddressOverlap(addr, ignoreIfaceNames)
}
if err != nil {
fatal(err)
}
os.Exit(0)
}
示例2: main
func main() {
flag.Parse()
if flLogLevel != "" {
lvl, err := logrus.ParseLevel(flLogLevel)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n", flLogLevel)
os.Exit(1)
}
logrus.SetLevel(lvl)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
if flDebug {
logrus.SetLevel(logrus.DebugLevel)
}
d, err := rbd.NewRbdDriver(root, graphOptions)
if err != nil {
logrus.Errorf("Create rbd driver failed: %v", err)
os.Exit(1)
}
h := degraph.NewHandler(d)
logrus.Infof("listening on %s\n", socketAddress)
fmt.Println(h.ServeUnix("root", socketAddress))
}
示例3: readConfig
func readConfig() {
var (
configFile string
showHelp, showVersion bool
)
logFilter = &logutils.LevelFilter{
Levels: logLevels,
MinLevel: logMinLevel,
Writer: os.Stderr,
}
log.SetOutput(logFilter)
flag.StringVar(&configFile, []string{"c", "-config"}, "/etc/logear/logear.conf", "config file")
flag.StringVar(&logFile, []string{"l", "-log"}, "", "log file")
flag.BoolVar(&showHelp, []string{"h", "-help"}, false, "display the help")
flag.BoolVar(&showVersion, []string{"v", "-version"}, false, "display version info")
flag.Parse()
if showHelp {
flag.Usage()
os.Exit(0)
}
if showVersion {
println(versionstring)
println("OS: " + runtime.GOOS)
println("Architecture: " + runtime.GOARCH)
os.Exit(0)
}
parseTomlFile(configFile)
startLogging()
log.Printf("%s started with pid %d", versionstring, os.Getpid())
}
示例4: init
func init() {
// Check https://github.com/docker/docker/blob/master/pkg/mflag/example/example.go
flag.StringVar(&path, []string{"p", "#pathhidden", "-path"}, "", "path to traverse")
flag.StringVar(&path, []string{"n", "#namehidden", "-name"}, "", "name to traverse")
flag.BoolVar(&h, []string{"h", "#help", "-help"}, false, "display the help")
flag.Parse()
}
示例5: main
func main() {
var (
justVersion bool
logLevel = "info"
c proxy.Config
withDNS bool
)
c.Version = version
mflag.BoolVar(&justVersion, []string{"#version", "-version"}, false, "print version and exit")
mflag.StringVar(&logLevel, []string{"-log-level"}, "info", "logging level (debug, info, warning, error)")
mflagext.ListVar(&c.ListenAddrs, []string{"H"}, nil, "addresses on which to listen")
mflag.StringVar(&c.HostnameFromLabel, []string{"-hostname-from-label"}, "", "Key of container label from which to obtain the container's hostname")
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.RewriteInspect, []string{"-rewrite-inspect"}, false, "Rewrite 'inspect' calls to return the weave network settings (if attached)")
mflag.BoolVar(&c.NoDefaultIPAM, []string{"#-no-default-ipam", "-no-default-ipalloc"}, false, "do not automatically allocate addresses for containers without a WEAVE_CIDR")
mflag.BoolVar(&c.NoRewriteHosts, []string{"-no-rewrite-hosts"}, false, "do not automatically rewrite /etc/hosts. Use if you need the docker IP to remain in /etc/hosts")
mflag.StringVar(&c.TLSConfig.CACert, []string{"#tlscacert", "-tlscacert"}, "", "Trust certs signed only by this CA")
mflag.StringVar(&c.TLSConfig.Cert, []string{"#tlscert", "-tlscert"}, "", "Path to TLS certificate file")
mflag.BoolVar(&c.TLSConfig.Enabled, []string{"#tls", "-tls"}, false, "Use TLS; implied by --tlsverify")
mflag.StringVar(&c.TLSConfig.Key, []string{"#tlskey", "-tlskey"}, "", "Path to TLS key file")
mflag.BoolVar(&c.TLSConfig.Verify, []string{"#tlsverify", "-tlsverify"}, false, "Use TLS and verify the remote")
mflag.BoolVar(&withDNS, []string{"#-with-dns", "#w"}, false, "option removed")
mflag.BoolVar(&c.WithoutDNS, []string{"-without-dns"}, false, "instruct created containers to never use weaveDNS as their nameserver")
mflag.BoolVar(&c.NoMulticastRoute, []string{"-no-multicast-route"}, false, "do not add a multicast route via the weave interface when attaching containers")
mflag.Parse()
if justVersion {
fmt.Printf("weave proxy %s\n", version)
os.Exit(0)
}
SetLogLevel(logLevel)
Log.Infoln("weave proxy", version)
Log.Infoln("Command line arguments:", strings.Join(os.Args[1:], " "))
if withDNS {
Log.Warning("--with-dns option has been removed; DNS is on by default")
}
c.Image = getenv("EXEC_IMAGE", "weaveworks/weaveexec")
c.DockerBridge = getenv("DOCKER_BRIDGE", "docker0")
c.DockerHost = getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
c.ProcPath = getenv("PROCFS", "/proc")
p, err := proxy.NewProxy(c)
if err != nil {
Log.Fatalf("Could not start proxy: %s", err)
}
defer p.Stop()
listeners := p.Listen()
p.AttachExistingContainers()
go p.Serve(listeners)
go p.ListenAndServeStatus("/home/weave/status.sock")
SignalHandlerLoop()
}
示例6: main
func main() {
var (
as []string
hostMatch string
)
mflagext.ListVar(&as, []string{"a", "-alias"}, []string{}, "Specify hostname aliases in the form alias:hostname. Can be repeated.")
mflag.StringVar(&hostMatch, []string{"h", "-host-match"}, "*.weave.local", "Specify main host shExpMatch expression in pacfile")
mflag.Parse()
var aliases = map[string]string{}
for _, a := range as {
parts := strings.SplitN(a, ":", 2)
if len(parts) != 2 {
fmt.Printf("'%s' is not a valid alias.\n", a)
mflag.Usage()
os.Exit(1)
}
aliases[parts[0]] = parts[1]
}
go socksProxy(aliases)
t := template.Must(template.New("pacfile").Parse(pacfile))
http.HandleFunc("/proxy.pac", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/x-ns-proxy-autoconfig")
t.Execute(w, pacFileParameters{hostMatch, aliases})
})
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
示例7: parseConf
// parse conf from env and args
func parseConf() {
// let mflag parse first
mflag.Parse()
// using gconf parse env
gconf, err := globalconf.NewWithOptions(&globalconf.Options{
EnvPrefix: "WICKET_",
})
if err != nil {
log.Fatalf("error parsing config file: %v", err)
}
fs := flag.NewFlagSet("", flag.ContinueOnError)
mflag.VisitAll(func(f *mflag.Flag) {
for _, n := range f.Names {
if len(n) < 2 {
continue
}
n = strings.TrimPrefix(n, "-")
fs.Var(f.Value, n, f.Usage)
}
})
gconf.ParseSet("", fs)
}
示例8: main
func main() {
mflag.BoolVar(&useScheduler, []string{"scheduler"}, false, "Use scheduler to distribute tests across shards")
mflag.BoolVar(&runParallel, []string{"parallel"}, false, "Run tests in parallel on hosts where possible")
mflag.Parse()
tests, err := getTests(mflag.Args())
if err != nil {
fmt.Printf("Error parsing tests: %v\n", err)
os.Exit(1)
}
hosts := strings.Fields(os.Getenv("HOSTS"))
maxHosts := len(hosts)
if maxHosts == 0 {
fmt.Print("No HOSTS specified.\n")
os.Exit(1)
}
var errored bool
if runParallel {
errored = parallel(tests, hosts)
} else {
errored = sequential(tests, hosts)
}
if errored {
os.Exit(1)
}
}
示例9: main
func main() {
mflag.BoolVar(&useScheduler, []string{"scheduler"}, false, "Use scheduler to distribute tests across shards")
mflag.BoolVar(&runParallel, []string{"parallel"}, false, "Run tests in parallel on hosts where possible")
mflag.BoolVar(&verbose, []string{"v"}, false, "Print output from all tests (Also enabled via DEBUG=1)")
mflag.StringVar(&schedulerHost, []string{"scheduler-host"}, defaultSchedulerHost, "Hostname of scheduler.")
mflag.Parse()
if len(os.Getenv("DEBUG")) > 0 {
verbose = true
}
tests, err := getTests(mflag.Args())
if err != nil {
fmt.Printf("Error parsing tests: %v\n", err)
os.Exit(1)
}
hosts := strings.Fields(os.Getenv("HOSTS"))
maxHosts := len(hosts)
if maxHosts == 0 {
fmt.Print("No HOSTS specified.\n")
os.Exit(1)
}
var errored bool
if runParallel {
errored = parallel(tests, hosts)
} else {
errored = sequential(tests, hosts)
}
if errored {
os.Exit(1)
}
}
示例10: main
func main() {
if reexec.Init() {
return
}
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
logrus.SetOutput(stderr)
flag.Merge(flag.CommandLine, clientFlags.FlagSet, commonFlags.FlagSet)
flag.Usage = func() {
fmt.Fprint(os.Stdout, "Usage: docker [OPTIONS] COMMAND [arg...]\n"+daemonUsage+" docker [ -h | --help | -v | --version ]\n\n")
fmt.Fprint(os.Stdout, "A self-sufficient runtime for containers.\n\nOptions:\n")
flag.CommandLine.SetOutput(os.Stdout)
flag.PrintDefaults()
help := "\nCommands:\n"
for _, cmd := range dockerCommands {
help += fmt.Sprintf(" %-10.10s%s\n", cmd.name, cmd.description)
}
help += "\nRun 'docker COMMAND --help' for more information on a command."
fmt.Fprintf(os.Stdout, "%s\n", help)
}
flag.Parse()
if *flVersion {
showVersion()
return
}
clientCli := client.NewDockerCli(stdin, stdout, stderr, clientFlags)
// TODO: remove once `-d` is retired
handleGlobalDaemonFlag()
if *flHelp {
// if global flag --help is present, regardless of what other options and commands there are,
// just print the usage.
flag.Usage()
return
}
c := cli.New(clientCli, daemonCli)
if err := c.Run(flag.Args()...); err != nil {
if sterr, ok := err.(cli.StatusError); ok {
if sterr.Status != "" {
fmt.Fprintln(os.Stderr, sterr.Status)
os.Exit(1)
}
os.Exit(sterr.StatusCode)
}
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
示例11: init
func init() {
flag.Bool([]string{"h", "-help"}, false, "Display help")
flag.BoolVar(&verbose, []string{"v", "-verbose"}, false, "Switch to verbose output")
flag.BoolVar(&print_digest, []string{"d", "-digest"}, false, "Print also digest of manifest")
flag.StringVar(&key, []string{"k", "-key-file"}, "", "Private key with which to sign")
flag.Parse()
}
示例12: init
func init() {
// Arguments for ssh server
flag.BoolVar(&h, []string{"h", "#help", "-help"}, false,
"display this help message")
flag.BoolVar(&server, []string{"s", "-server"}, false,
"start the server")
flag.StringVar(&listen, []string{"l", "-listen"}, "0.0.0.0",
"start the server")
flag.IntVar(&port, []string{"p", "-port"}, 5566,
"port to listen")
flag.StringVar(&user, []string{"-user"}, "sshcam",
"username for SSH login")
flag.StringVar(&pass, []string{"-pass"}, "[email protected]",
"password for SSH login")
// Arguments for img2xterm
flag.BoolVar(&colorful, []string{"c", "-color"}, false,
"turn on color")
flag.BoolVar(&asciiOnly, []string{"-ascii-only"}, false,
"fallback to use ASCII's full block characters")
flag.StringVar(&distanceAlgorithm, []string{"-color-algorithm"}, "yiq",
"algorithm use to compute colors. Available options are:\n"+
"'rgb': simple linear distance in RGB colorspace\n"+
"'yiq': simple linear distance in YIQ colorspace (the default)\n"+
"'cie94': use the CIE94 formula")
flag.IntVar(&maxFPS, []string{"-max-fps"}, 4,
"limit the maximum FPS")
flag.StringVar(&device, []string{"-device"}, "/dev/video0",
"the webcam device to open")
flag.StringVar(&sizeFlag, []string{"-size"}, "640x480",
"image dimension, must be supported by the device")
flag.Parse()
size = wxh2Size(sizeFlag)
}
示例13: init
func init() {
flag.StringVar(&tplfile, []string{"t", "-template"}, "", "Template file name for produce config file.")
flag.StringVar(&appName, []string{"-app"}, "appname", "App name for upstream/logfile name/conf name/consul key.")
flag.StringVar(&output, []string{"o", "-output"}, "appname.conf", "Config file name for save config file.")
flag.BoolVar(&help, []string{"h", "-help"}, false, "Display the help")
flag.Parse()
}
示例14: init
func init() {
flag.BoolVar(&help, []string{"h", "-help"}, false, "Display help")
flag.BoolVar(&verbose, []string{"v", "-verbose"}, false, "Switch to verbose output")
flag.Var(&keys, []string{"k", "-key-file"}, "Private key with which to sign")
flag.Parse()
if kk := flag.Lookup("-k"); kk != nil {
keys = *kk.Value.(*opts.ListOpts)
}
}
示例15: dnetCommand
func dnetCommand(stdout, stderr io.Writer) error {
flag.Parse()
if *flHelp {
flag.Usage()
return nil
}
if *flLogLevel != "" {
lvl, err := logrus.ParseLevel(*flLogLevel)
if err != nil {
fmt.Fprintf(stderr, "Unable to parse logging level: %s\n", *flLogLevel)
return err
}
logrus.SetLevel(lvl)
} else {
logrus.SetLevel(logrus.InfoLevel)
}
if *flDebug {
logrus.SetLevel(logrus.DebugLevel)
}
if *flHost == "" {
defaultHost := os.Getenv("DNET_HOST")
if defaultHost == "" {
// TODO : Add UDS support
defaultHost = fmt.Sprintf("tcp://%s:%d", DefaultHTTPHost, DefaultHTTPPort)
}
*flHost = defaultHost
}
dc, err := newDnetConnection(*flHost)
if err != nil {
if *flDaemon {
logrus.Error(err)
} else {
fmt.Fprint(stderr, err)
}
return err
}
if *flDaemon {
err := dc.dnetDaemon()
if err != nil {
logrus.Errorf("dnet Daemon exited with an error : %v", err)
}
return err
}
cli := client.NewNetworkCli(stdout, stderr, dc.httpCall)
if err := cli.Cmd("dnet", flag.Args()...); err != nil {
fmt.Fprintln(stderr, err)
return err
}
return nil
}