當前位置: 首頁>>代碼示例>>Golang>>正文


Golang flag.Usage函數代碼示例

本文整理匯總了Golang中flag.Usage函數的典型用法代碼示例。如果您正苦於以下問題:Golang Usage函數的具體用法?Golang Usage怎麽用?Golang Usage使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Usage函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	flag.Usage = Usage
	flag.Parse()

	if *showVersion {
		fmt.Println("goobar", Version)
		os.Exit(0)
	}

	if *listenAddress == "" {
		fmt.Fprintln(os.Stderr, "you must supply an address to listen on")
		flag.Usage()
		os.Exit(1)
	}

	if *memcacheBackend == "" {
		fmt.Fprintln(os.Stderr, "you must specify a memcached backend")
		flag.Usage()
		os.Exit(1)
	}

	log.SetPrefix("goobar ")
	log.SetFlags(log.Ldate | log.Lmicroseconds)

	tsock, err := net.Listen("tcp", *listenAddress)
	if err != nil {
		panic(err)
	}

	server.Main(tsock)
}
開發者ID:sofuture,項目名稱:goobar,代碼行數:31,代碼來源:goobar.go

示例2: main

func main() {
	flag.Usage = usage
	flag.Parse()
	cachingHTTPClient = util.CachingHttpClient()

	if *tokenFlag == "" || cachingHTTPClient == nil {
		flag.Usage()
		return
	}

	ds = clientFlags.CreateDataset()
	if ds == nil {
		flag.Usage()
		return
	}
	defer ds.Store().Close()

	if err := clientFlags.CreateProgressFile(); err != nil {
		fmt.Println(err)
	} else {
		defer clientFlags.CloseProgressFile()
	}

	token := oauth2.Token{AccessToken: *tokenFlag}
	authHTTPClient = oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(&token))

	start = time.Now()
	var user = getUser()
	printStats(user)

	userRef := ds.Store().WriteValue(user)
	fmt.Printf("userRef: %s\n", userRef.TargetRef())
	_, err := ds.Commit(userRef)
	d.Exp.NoError(err)
}
開發者ID:arv,項目名稱:noms-old,代碼行數:35,代碼來源:facebook.go

示例3: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s size\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "    Must specify an odd integer for size\n")
		flag.PrintDefaults()
	}
	flag.Parse()
	if flag.NArg() != 1 {
		flag.Usage()
		return
	}
	size, err := strconv.Atoi(flag.Arg(0))
	if err != nil {
		flag.Usage()
		return
	}
	square, err := magicsquare.MagicSquare(size)
	if err != nil {
		flag.Usage()
		return
	}
	for _, row := range square {
		for _, col := range row {
			fmt.Printf("%5v", col)
		}
		fmt.Printf("\n")
	}

}
開發者ID:jmcvetta,項目名稱:magicsquare,代碼行數:29,代碼來源:main.go

示例4: cmdCreateTeam

func cmdCreateTeam() {
	if flagCmdCreateTeam {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			flag.Usage()
			os.Exit(1)
		}

		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		c := &api.Context{}
		c.RequestId = model.NewId()
		c.IpAddress = "cmd_line"

		team := &model.Team{}
		team.DisplayName = flagTeamName
		team.Name = flagTeamName
		team.Email = flagEmail
		team.Type = model.TEAM_INVITE

		api.CreateTeam(c, team)
		if c.Err != nil {
			if c.Err.Message != "A team with that domain already exists" {
				l4g.Error("%v", c.Err)
				flushLogAndExit(1)
			}
		}

		os.Exit(0)
	}
}
開發者ID:cbayleOL,項目名稱:platform,代碼行數:35,代碼來源:mattermost.go

示例5: main

// Remember Exit(0) is success, Exit(1) is failure
func main() {
	flag.Var(&slaveList, "control", "list of ip:port addresses to control")
	flag.Parse()
	if len(*testUrl) == 0 {
		flag.Usage()
		os.Exit(1)
	}
	if len(slaveList) > 0 && *listen != 0 {
		fmt.Fprintf(os.Stderr, "You can't have both --listen and --control flags")
		flag.Usage()
		os.Exit(1)
	}
	rand.Seed(time.Now().Unix())

	// set up logging
	logWriter, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
	if err != nil {
		println(err)
		os.Exit(1)
	}
	log.SetOutput(logWriter)

	TRACE = log.New(ioutil.Discard,
		"TRACE: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	INFO = log.New(logWriter,
		"INFO: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	ERROR = log.New(logWriter,
		"ERROR: ",
		log.Ldate|log.Ltime|log.Lshortfile)
	INFO.Println("beginning run")

	os.Exit(realMain())
}
開發者ID:kgoess,項目名稱:webserver-loadtest,代碼行數:36,代碼來源:webserver-loadtest.go

示例6: main

func main() {
	token := os.Getenv("GITHUB_ACCESS_TOKEN")
	client := github.NewClient(token)

	flag.Usage = func() { fmt.Print(usage) }
	flag.Parse()

	args := flag.Args()
	if len(args) == 0 {
		flag.Usage()
		os.Exit(1)
	}
	switch args[0] {
	case "create":
		create(client, args[1:])
	case "show":
		show(client, args[1:])
	case "search":
		search(client, args[1:])
	case "edit":
		edit(client, args[1:])
	case "close":
		close(client, args[1:])
	case "reopen":
		reopen(client, args[1:])
	default:
		flag.Usage()
		os.Exit(1)
	}
}
開發者ID:seikichi,項目名稱:gopl,代碼行數:30,代碼來源:issues.go

示例7: commands

func commands(args []string) {
	var cfg config
	var err error

	fmt.Println(args)

	if len(args) == 0 {
		flag.Usage()
		return
	}

	switch args[0] {
	case "new":
		path := args[1]
		if path == "" {
			flag.Usage()
			os.Exit(1)
		}
		err = cfg.New(path)
		checkFatal(err)
	case "build":
		err = cfg.load("_config.yml")
		checkFatal(err)
		err = cfg.Build()
		checkFatal(err)
	case "serve":
		err = cfg.load("_config.yml")
		checkFatal(err)
		err = cfg.Serve()
		checkFatal(err)
	default:
		flag.Usage()
	}
}
開發者ID:NovemberFoxtrot,項目名稱:jedie,代碼行數:34,代碼來源:jedie.go

示例8: init

func init() {
	flag.StringVar(&in, "in", "", "BAM file to be processed.")
	flag.StringVar(&annot, "annot", "", "file name of a GFF file containing annotations.")
	flag.Float64Var(&thresh, "thresh", 1, "log score threshold for inclusion of feature.")
	flag.Var(&classes, "class", "comma separated set of annotation classes to analyse.")
	flag.BoolVar(&pretty, "pretty", true, "outfile JSON data indented.")
	flag.IntVar(&minLength, "min", 20, "minimum length read considered.")
	flag.IntVar(&maxLength, "max", 35, "maximum length read considered.")
	flag.IntVar(&minId, "minid", 90, "minimum percentage identity for mapped bases.")
	flag.IntVar(&minQ, "minQ", 20, "minimum per-base sequence quality.")
	flag.Float64Var(&minAvQ, "minAvQ", 30, "minimum average per-base sequence quality.")
	flag.IntVar(&mapQ, "mapQ", 0, "minimum mapping quality [0, 255).")
	flag.IntVar(&binLength, "bin", 1e7, "bin length.")
	help := flag.Bool("help", false, "output this usage message.")
	flag.Parse()
	mapQb = byte(mapQ)
	if *help {
		flag.Usage()
		os.Exit(0)
	}
	if in == "" || !annotOK(annot, classes) || mapQ < 0 || mapQ > 254 {
		flag.Usage()
		os.Exit(1)
	}
}
開發者ID:henmt,項目名稱:2015,代碼行數:25,代碼來源:trans-diff.go

示例9: main

func main() {
	help := flag.Bool("help", false, "show this message")
	inFile := flag.String("in", "", "input filename (required)")
	outFile := flag.String("out", "", "output filename (stdout if omitted)")

	flag.Parse()

	if *help {
		flag.Usage()
		os.Exit(0)
	}

	if len(*inFile) == 0 {
		flag.Usage()
		os.Exit(0)
	}

	pr := codejam.NewProblem(*inFile, *outFile)

	numTestCases := pr.ReadInt()

	if numTestCases < 1 {
		panic(fmt.Errorf("no testcases available"))
	}

	for testIndex := 1; testIndex <= numTestCases; testIndex++ {
		d := parse(pr, testIndex)
		solve(pr, d)
	}

	pr.Close()
}
開發者ID:uwedeportivo,項目名稱:codejam,代碼行數:32,代碼來源:main.go

示例10: cmdAssignRole

func cmdAssignRole() {
	if flagCmdAssignRole {
		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		if !model.IsValidUserRoles(flagRole) {
			fmt.Fprintln(os.Stderr, "flag invalid argument: -role")
			flag.Usage()
			os.Exit(1)
		}

		c := getMockContext()

		var user *model.User
		if result := <-api.Srv.Store.User().GetByEmail(flagEmail); result.Err != nil {
			l4g.Error("%v", result.Err)
			flushLogAndExit(1)
		} else {
			user = result.Data.(*model.User)
		}

		if !user.IsInRole(flagRole) {
			api.UpdateUserRoles(c, user, flagRole)
		}

		os.Exit(0)
	}
}
開發者ID:lfbrock,項目名稱:platform,代碼行數:31,代碼來源:mattermost.go

示例11: realMain

func realMain() int {
	flag.Parse()
	if help {
		flag.Usage()
		fmt.Fprint(os.Stderr, "Flags:\n")
		fmt.Fprint(os.Stderr, "\n")
		flag.PrintDefaults()
		return 0
	}

	worker.files = flag.Args() // this is the list of files
	if len(worker.files) == 0 {
		flag.Usage()
		return 1
	}
	err := worker.Work()
	if err != nil {
		if err == ErrProcess {
			return len(worker.errs) // the number of operations (files) that errored is the return code
		}
		return 1
	}

	return 0
}
開發者ID:mohae,項目名稱:peu,代碼行數:25,代碼來源:main.go

示例12: cmdCreateTeam

func cmdCreateTeam() {
	if flagCmdCreateTeam {
		if len(flagTeamName) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -team_name")
			flag.Usage()
			os.Exit(1)
		}

		if len(flagEmail) == 0 {
			fmt.Fprintln(os.Stderr, "flag needs an argument: -email")
			flag.Usage()
			os.Exit(1)
		}

		c := getMockContext()

		team := &model.Team{}
		team.DisplayName = flagTeamName
		team.Name = flagTeamName
		team.Email = flagEmail
		team.Type = model.TEAM_OPEN

		api.CreateTeam(c, team)
		if c.Err != nil {
			if c.Err.Id != "store.sql_team.save.domain_exists.app_error" {
				l4g.Error("%v", c.Err)
				flushLogAndExit(1)
			}
		}

		os.Exit(0)
	}
}
開發者ID:lfbrock,項目名稱:platform,代碼行數:33,代碼來源:mattermost.go

示例13: main

func main() {
	var ihelp *bool = flag.Bool("h", false, "Print help information")
	var iport *int = flag.Int("p", 6666, "Port number")
	var iverb *int = flag.Int("v", 1, "Verbosity (0-6)")
	var idrop *int = flag.Int("r", 0, "Network packet drop percentage")
	var elim *int = flag.Int("k", 5, "Epoch limit")
	var ems *int = flag.Int("d", 2000, "Epoch duration (millisecconds)")
	flag.Parse()
	if *ihelp {
		flag.Usage()
		os.Exit(0)
	}
	var port int = *iport
	if flag.NArg() > 0 {
		nread, _ := fmt.Sscanf(flag.Arg(0), "%d", &port)
		if nread != 1 {
			flag.Usage()
			os.Exit(0)
		}
	}
	params := &lsp12.LspParams{*elim, *ems}

	lsplog.SetVerbose(*iverb)
	lspnet.SetWriteDropPercent(*idrop)
	fmt.Printf("Establishing server on port %d\n", port)
	srv, err := lsp12.NewLspServer(port, params)
	if err != nil {
		fmt.Printf("... failed.  Error message %s\n", err.Error())
	} else {
		runserver(srv)
	}
}
開發者ID:ammarar,項目名稱:DecentralizedLoadBalancer,代碼行數:32,代碼來源:echoserver.go

示例14: main

func main() {
	flag.Parse()

	if email == "" || password == "" {
		fmt.Println("Invalid E-Mail or Password\n")
		flag.Usage()
		os.Exit(-1)
	}

	if flag.NArg() != 2 {
		flag.Usage()
		os.Exit(-1)
	}
	imsi := flag.Arg(0)
	protection := flag.Arg(1)

	c, err := goracom.NewClient(email, password)
	errToExit(err)
	s := c.NewSubscriber()
	if protection == "false" {
		sub, err := s.EnableTerminate(imsi)
		errToExit(err)
		printSubscriber(*sub)
	} else {
		sub, err := s.DisableTerminate(imsi)
		errToExit(err)
		printSubscriber(*sub)
	}
}
開發者ID:135yshr,項目名稱:goracom,代碼行數:29,代碼來源:terminate.go

示例15: main

func main() {
	flag.Parse()
	if helpFlag {
		flag.Usage()
		os.Exit(0)
	}
	if len(upstreamUrl) == 0 {
		fmt.Println("Missing argument -upstream")
		flag.Usage()
		os.Exit(1)
	}
	if len(dataplaneUrl) == 0 {
		fmt.Println("Missing argument -dataplane")
		flag.Usage()
		os.Exit(1)
	}
	notifier := gbp.NewNotifier(upstreamUrl, listenSocket)
	if err := notifier.NotifyEndpointUp(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	g, err := gbp.NewServer(upstreamUrl, dataplaneUrl)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	gbp.Info.Printf("GBP Server listening on %s\n", listenSocket)
	http.ListenAndServe(listenSocket, g.Handler())
}
開發者ID:iovisor,項目名稱:iomodules,代碼行數:29,代碼來源:main.go


注:本文中的flag.Usage函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。