func parseFlags(args []string) (*config.Config, error) { var doHelp bool var doVersion bool var c = config.DefaultConfig() flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError) flags.Usage = func() { fmt.Println(Help()) } flags.BoolVar(&doHelp, "help", false, "") flags.BoolVar(&doVersion, "version", false, "") flags.StringVar(&c.LogLevel, "log-level", "WARN", "") flags.DurationVar(&c.Refresh, "refresh", time.Minute, "") flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "") flags.StringVar(&c.MesosIpOrder, "mesos-ip-order", "netinfo,mesos,host", "") flags.BoolVar(&c.Healthcheck, "healthcheck", false, "") flags.StringVar(&c.HealthcheckIp, "healthcheck-ip", "127.0.0.1", "") flags.StringVar(&c.HealthcheckPort, "healthcheck-port", "24476", "") flags.Var((funcVar)(func(s string) error { c.WhiteList = append(c.WhiteList, s) return nil }), "whitelist", "") flags.StringVar(&c.ServiceName, "service-name", "mesos", "") flags.StringVar(&c.ServiceTags, "service-tags", "", "") consul.AddCmdFlags(flags) if err := flags.Parse(args); err != nil { return nil, err } args = flags.Args() if len(args) > 0 { return nil, fmt.Errorf("extra argument(s): %q", args) } if doVersion { fmt.Printf("%s v%s\n", Name, Version) os.Exit(0) } if doHelp { flags.Usage() os.Exit(0) } l, err := log.ParseLevel(strings.ToLower(c.LogLevel)) if err != nil { log.SetLevel(log.WarnLevel) log.Warnf("Invalid log level '%v'. Setting to WARN", c.LogLevel) } else { log.SetLevel(l) } return c, nil }
func parseFlags(args []string) (*config.Config, error) { var doHelp bool var c = config.DefaultConfig() flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError) flags.Usage = func() { fmt.Println(Help()) } flags.BoolVar(&doHelp, "help", false, "") flags.StringVar(&c.LogLevel, "log-level", "WARN", "") flags.DurationVar(&c.Refresh, "refresh", time.Minute, "") flags.StringVar(&c.RegistryPort, "registry-port", "8500", "") flags.Var((*config.AuthVar)(c.RegistryAuth), "registry-auth", "") flags.BoolVar(&c.RegistrySSL.Enabled, "registry-ssl", c.RegistrySSL.Enabled, "") flags.BoolVar(&c.RegistrySSL.Verify, "registry-ssl-verify", c.RegistrySSL.Verify, "") flags.StringVar(&c.RegistrySSL.Cert, "registry-ssl-cert", c.RegistrySSL.Cert, "") flags.StringVar(&c.RegistrySSL.CaCert, "registry-ssl-cacert", c.RegistrySSL.CaCert, "") flags.StringVar(&c.RegistryToken, "registry-token", c.RegistryToken, "") flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "") consul.AddCmdFlags(flags) if err := flags.Parse(args); err != nil { return nil, err } args = flags.Args() if len(args) > 0 { return nil, fmt.Errorf("extra argument(s): %q", args) } if doHelp { flags.Usage() os.Exit(0) } l, err := log.ParseLevel(c.LogLevel) if err != nil { log.SetLevel(log.WarnLevel) log.Warnf("Invalid log level '%v'. Setting to WARN") } else { log.SetLevel(l) } return c, nil }
func parseFlags(args []string) (*config.Config, error) { var doHelp bool var c = config.DefaultConfig() flags := flag.NewFlagSet("mesos-consul", flag.ContinueOnError) flags.Usage = func() { fmt.Println(Help()) } flags.BoolVar(&doHelp, "help", false, "") flags.StringVar(&c.LogLevel, "log-level", "WARN", "") flags.DurationVar(&c.Refresh, "refresh", time.Minute, "") flags.StringVar(&c.Zk, "zk", "zk://127.0.0.1:2181/mesos", "") flags.StringVar(&c.MesosIpOrder, "mesos-ip-order", "netinfo,mesos,host", "") consul.AddCmdFlags(flags) if err := flags.Parse(args); err != nil { return nil, err } args = flags.Args() if len(args) > 0 { return nil, fmt.Errorf("extra argument(s): %q", args) } if doHelp { flags.Usage() os.Exit(0) } l, err := log.ParseLevel(strings.ToLower(c.LogLevel)) if err != nil { log.SetLevel(log.WarnLevel) log.Warnf("Invalid log level '%v'. Setting to WARN", c.LogLevel) } else { log.SetLevel(l) } return c, nil }