コード例 #1
0
ファイル: facettectl.go プロジェクト: carriercomm/facette
func main() {
	var handler func(*config.Config, []string) error

	cfg := &config.Config{}

	if err := cfg.Load(flagConfig); err != nil {
		fmt.Println("Error: " + err.Error())
		os.Exit(1)
	}

	if len(flag.Args()) == 0 {
		cmd.PrintUsage(os.Stderr, cmdUsage)
	}

	switch flag.Args()[0] {
	case "refresh":
		handler = handleService
	default:
		cmd.PrintUsage(os.Stderr, cmdUsage)
		os.Exit(1)
	}

	err := handler(cfg, flag.Args())
	if err == os.ErrInvalid {
		cmd.PrintUsage(os.Stderr, cmdUsage)
	} else if err != nil {
		fmt.Fprintln(os.Stderr, "Error: "+err.Error())
	}
}
コード例 #2
0
ファイル: facettectl.go プロジェクト: carriercomm/facette
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)
	}
}
コード例 #3
0
ファイル: facette.go プロジェクト: carriercomm/facette
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)
	}
}