Example #1
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)
	}
}
Example #2
0
func init() {
	flag.StringVar(&flagConfig, "c", config.DefaultConfigFile, "configuration file path")
	flag.BoolVar(&flagHelp, "h", false, "display this help and exit")
	flag.StringVar(&flagLog, "l", config.DefaultLogFile, "log file path")
	flag.StringVar(&flagLogLevel, "L", config.DefaultLogLevel, "logging level")
	flag.BoolVar(&flagVersion, "V", false, "display software version and exit")
	flag.Usage = func() { utils.PrintUsage(os.Stderr, cmdUsage) }
	flag.Parse()

	if flagHelp {
		utils.PrintUsage(os.Stdout, cmdUsage)
	} else if flagVersion {
		utils.PrintVersion(version)
		os.Exit(0)
	} else if flagConfig == "" {
		fmt.Fprintf(os.Stderr, "Error: configuration file path is mandatory\n")
		utils.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)
	}
}