示例#1
0
文件: zkcmd.go 项目: ZhuoRoger/vitess
func main() {
	opts.Parse()
	args := opts.Args
	if len(args) == 0 {
		opts.Help()
		os.Exit(1)
	}

	if *zkAddrs != "" {
		if *zkoccAddr != "" {
			log.Fatalf("zk.addrs and zk.zkocc-addr are mutually exclusive")
		}
		var err error
		zconn, _, err = zk.DialZkTimeout(*zkAddrs, 5*time.Second, 10*time.Second)
		if err != nil {
			log.Fatalf("zk connect failed: %v", err.Error())
		}
	}

	if *zkoccAddr != "" {
		var err error
		zconn, err = zk.DialZkocc(*zkoccAddr, 5*time.Second)
		if err != nil {
			log.Fatalf("zkocc connect failed: %v", err.Error())
		}
	}

	cmdName := args[0]
	args = args[1:]
	if cmd, ok := cmdMap[cmdName]; ok {
		cmd(args)
	} else {
		opts.Help()
	}
}
示例#2
0
func main() {
	defer logutil.Flush()
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %v:\n", os.Args[0])
		flag.PrintDefaults()
		fmt.Fprintf(os.Stderr, doc)
	}
	flag.Parse()
	args := flag.Args()
	if len(args) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	if *zkAddrs != "" {
		if *zkoccAddr != "" {
			log.Fatalf("zk.addrs and zk.zkocc-addr are mutually exclusive")
		}
		var err error
		zconn, _, err = zk.DialZkTimeout(*zkAddrs, 5*time.Second, 10*time.Second)
		if err != nil {
			log.Fatalf("zk connect failed: %v", err.Error())
		}
	}

	if *zkoccAddr != "" {
		var err error
		zconn, err = zk.DialZkocc(*zkoccAddr, 5*time.Second)
		if err != nil {
			log.Fatalf("zkocc connect failed: %v", err.Error())
		}
	}

	cmdName := args[0]
	args = args[1:]
	if cmd, ok := cmdMap[cmdName]; ok {
		subFlags := flag.NewFlagSet(cmdName, flag.ExitOnError)
		cmd(subFlags, args)
	}
}