Beispiel #1
0
func init() {
	flag.StringVar(&flagConfig, "c", defaultConfigFile, "configuration file path")
	flag.BoolVar(&flagHelp, "h", false, "display this help and exit")
	flag.BoolVar(&flagVersion, "V", false, "display software version and exit")
	flag.Usage = func() { cmd.PrintUsage(os.Stderr, cmdUsage) }
	flag.Parse()

	if flagHelp {
		cmd.PrintUsage(os.Stdout, cmdUsage)
	} else if flagVersion {
		cmd.PrintVersion(version, buildDate)
		os.Exit(0)
	} else if flagConfig == "" {
		fmt.Fprintf(os.Stderr, "Error: configuration file path is mandatory\n")
		cmd.PrintUsage(os.Stderr, cmdUsage)
	}
}
Beispiel #2
0
func init() {
	flag.StringVar(&flagConfig, "c", defaultConfigFile, "configuration file path")
	flag.BoolVar(&flagHelp, "h", false, "display this help and exit")
	flag.StringVar(&flagLogPath, "l", defaultLogPath, "log file path")
	flag.StringVar(&flagLogLevel, "L", defaultLogLevel, "logging level (error, warning, notice, info, debug)")
	flag.BoolVar(&flagVersion, "V", false, "display software version and exit")
	flag.Usage = func() { cmd.PrintUsage(os.Stderr, cmdUsage) }
	flag.Parse()

	if flagHelp {
		cmd.PrintUsage(os.Stdout, cmdUsage)
	} else if flagVersion {
		cmd.PrintVersion(version, buildDate)

		connectors := []string{}
		for connector := range connector.Connectors {
			connectors = append(connectors, connector)
		}

		sort.Strings(connectors)

		fmt.Printf("\nAvailable connectors:\n")
		for _, connector := range connectors {
			fmt.Printf("   %s\n", connector)
		}

		os.Exit(0)
	} else if flagConfig == "" {
		fmt.Fprintf(os.Stderr, "Error: configuration file path is mandatory\n")
		cmd.PrintUsage(os.Stderr, cmdUsage)
	}

	if logLevel, err = logger.GetLevelByName(flagLogLevel); err != nil {
		fmt.Fprintf(os.Stderr, "Error: invalid log level `%s'\n", flagLogLevel)
		os.Exit(1)
	}
}