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


Golang pflag.Usage函數代碼示例

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


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

示例1: positive

func positive(i int64) bool {
	if i < 0 {
		flag.Usage()
		return false
	}
	return true
}
開發者ID:habajca,項目名稱:simple-log-search,代碼行數:7,代碼來源:main.go

示例2: main

func main() {
	var config Config
	flag.BoolVar(&DEBUG, "debug", false, "enable debug logging")
	flag.BoolVar(&QUIET, "quiet", false, "disable output")
	flag.StringVar(&config.FieldSep, "csv-fields-terminated-by", "\t", "field separator")
	flag.StringVar(&config.RowSep, "csv-records-terminated-by", "\n", "row separator")
	flag.StringVar(&config.NullString, "csv-null-string", "\\N", "output string for NULL values")
	flag.BoolVar(&config.DateEpoch, "epoch", true, "output datetime as epoch instead of RFC3339")
	defaults_file := flag.String("defaults-file", "my.cnf", "defaults file")
	defaults_group_suffix := flag.String("defaults-group-suffix", "", "defaults group suffix")
	format := flag.String("format", "json", "output format 'json' or 'csv'")
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: mysqlcsvdump [options] database table > output.json\n\n")
		fmt.Fprintf(os.Stderr, "Reads connection info from ./my.cnf. Use '-' for table to send query in stdin\n\n")
		flag.PrintDefaults()
	}
	flag.Parse()

	args := flag.Args()
	if len(args) < 2 {
		flag.Usage()
		os.Exit(1)
	}
	dsn := getDSN(*defaults_file, "client"+*defaults_group_suffix, args[0])
	rows := getRows(dsn, args[1])
	if *format == "json" {
		NewJsonWriter(&config).WriteRows(rows)
	} else {
		NewCsvWriter(&config).WriteRows(rows)
	}
}
開發者ID:hzarka,項目名稱:mysqlbqdump,代碼行數:31,代碼來源:mysqlbqdump.go

示例3: main

func main() {
	var widthstr string
	flag.StringVarP(&widthstr, "width", "w", "100%",
		"Output width. Supports column count, percentage and decimals.")
	flag.Usage = usage
	flag.Parse()

	if len(flag.Args()) == 0 {
		flag.Usage()
		os.Exit(1)
	}

	width := getColumns(widthstr) - 1 // -1 for the reset column
	for _, fpath := range flag.Args() {
		im := aimg.NewImage(width)
		handleErr(im.ParseFile(fpath))

		if terminal.IsTerminal(os.Stdout) {
			fmt.Print(im.BlankReset())
		}
		im.WriteTo(os.Stdout)

		w, h := im.ActualSize()
		fmt.Println("File:", filepath.Base(fpath), "size:", w, "x", h)
	}
}
開發者ID:mehulsbhatt,項目名稱:aimg,代碼行數:26,代碼來源:main.go

示例4: identify_pipe

func identify_pipe() {
	stat, _ := os.Stdin.Stat()
	if (stat.Mode() & os.ModeCharDevice) == 0 {
		reader := bufio.NewReader(os.Stdin)
		printID(encode(reader))
	} else {
		flag.Usage()
	}
}
開發者ID:etcenter,項目名稱:c4,代碼行數:9,代碼來源:id_main.go

示例5: main

func main() {
	flag.Parse()
	if !valid() {
		flag.Usage()
		os.Exit(1)
	}

	if len(os.Args) < 2 {
		flag.Usage()
		os.Exit(1)
	}
	directory := os.Args[1]
	if generateTestFiles {
		if len(os.Args) < 4 {
			flag.Usage()
			os.Exit(1)
		}
		domainsFilename := os.Args[2]
		_, err := generation.GenerateTestData(
			directory,
			fileCount, rowCount,
			timeOrigin, timeFrame,
			uidCount,
			domainsFilename,
			util.GeoPoint(geo), distance,
		)
		if err != nil {
			fmt.Fprint(os.Stderr, err)
			os.Exit(1)
		}
		return
	}
	err := search.OutputSearchResults(
		directory,
		timeOrigin, timeFrame,
		util.GeoPoint(geo), distance,
	)
	if err != nil {
		fmt.Fprint(os.Stderr, err)
		os.Exit(1)
	}
}
開發者ID:habajca,項目名稱:simple-log-search,代碼行數:42,代碼來源:main.go

示例6: main

func main() {
	// Basic user configuration variables
	force := pflag.BoolP("force", "f", false, "Force output to terminal.")
	count := pflag.StringP("count", "n", "+Inf", "Number of random bytes to generate.")
	procs := pflag.IntP("procs", "p", runtime.NumCPU(), "Maximum number of concurrent workers.")
	pflag.Parse()

	if !(*force) && terminal.IsTerminal(int(os.Stdout.Fd())) {
		fmt.Fprintf(os.Stderr, "Random data not written to terminal.\n\n")
		pflag.Usage()
		os.Exit(1)
	}
	cnt, err := strconv.ParsePrefix(*count, strconv.AutoParse)
	if err != nil || math.IsNaN(cnt) {
		fmt.Fprintf(os.Stderr, "Number of bytes to generate is invalid.\n\n")
		pflag.Usage()
		os.Exit(1)
	}
	if (*procs) < 1 {
		fmt.Fprintf(os.Stderr, "Number of workers must be positive.\n\n")
		pflag.Usage()
		os.Exit(1)
	}

	runtime.GOMAXPROCS(*procs)
	rand.SetNumRoutines(*procs)

	// Copy random data to stdout
	if int64(cnt) < 0 || math.IsInf(cnt, 0) {
		_, err = io.Copy(os.Stdout, rand.Reader)
	} else {
		_, err = io.CopyN(os.Stdout, rand.Reader, int64(cnt))
	}
	if perr, ok := err.(*os.PathError); ok && perr.Err == syscall.EPIPE {
		err = nil // Expected error is for the sink to close the pipe
	} else if err != nil {
		panic(err)
	}
}
開發者ID:dsnet,項目名稱:crypto,代碼行數:39,代碼來源:main.go

示例7: main

func main() {
	flag.Usage = func() {
		fmt.Fprint(os.Stderr, Usage)
	}

	flag.IntVarP(&options.Port, "port", "p", 8080, "")
	flag.StringVar(&options.CustomCSS, "custom-css", "", "")

	flag.Parse()

	options.Dir = flag.Arg(0)

	if options.Dir == "" {
		flag.Usage()
		os.Exit(1)
	}

	log.Println("Serving wiki from", options.Dir)

	// Parse base template
	var err error
	options.template, err = template.New("base").Parse(Template)
	if err != nil {
		log.Fatalln("Error parsing HTML template:", err)
	}

	// Trim trailing slash from root path
	if strings.HasSuffix(options.Dir, "/") {
		options.Dir = options.Dir[:len(options.Dir)-1]
	}

	// Verify that the wiki folder exists
	_, err = os.Stat(options.Dir)
	if os.IsNotExist(err) {
		log.Fatalln("Directory not found")
	}

	// Check if the wiki folder is a Git repository
	options.git = IsGitRepository(options.Dir)
	if options.git {
		log.Println("Git repository found in directory")
	} else {
		log.Println("No git repository found in directory")
	}

	http.Handle("/api/diff/", commonHandler(DiffHandler))
	http.Handle("/", commonHandler(WikiHandler))

	log.Println("Listening on:", options.Port)
	http.ListenAndServe(fmt.Sprintf(":%d", options.Port), nil)
}
開發者ID:sguzwf,項目名稱:go-wiki,代碼行數:51,代碼來源:main.go

示例8: main

func main() {
	if len(os.Args) < 2 {
		flag.Usage()
		os.Exit(0)
	}

	switch os.Args[1] {
	case "-h", "--help":
		flag.Usage()
		os.Exit(0)
	case "-version":
		fmt.Fprintf(os.Stderr, versionString())
		os.Exit(0)
	case "id":
		if err := id_flags.Parse(os.Args[2:]); err == nil {
			id_main(id_flags)
		}
	case "cp":
		if err := cp_flags.Parse(os.Args[2:]); err == nil {
			cp_main(cp_flags)
		}
	}
}
開發者ID:etcenter,項目名稱:c4,代碼行數:23,代碼來源:main.go

示例9: main

func main() {
	pflag.Usage = func() {
		fmt.Fprintf(os.Stderr, USAGE)
	}

	var output = pflag.StringP("output", "o", ".", "output directory")
	pflag.Parse()

	if pflag.NArg() == 1 {
		genRoutes(pflag.Arg(0), *output)
	} else {
		pflag.Usage()
	}
}
開發者ID:qyfbq123,項目名稱:freedom-routes,代碼行數:14,代碼來源:main.go

示例10: main

func main() {
	board, id, err := parseThreadId(flag.Arg(0))
	if err != nil {
		fmt.Printf("Invalid input: %s\n", flag.Arg(0))
		flag.Usage()
		os.Exit(1)
	}

	ticker := time.NewTicker(*refresh)
	for {
		log.Println("Loading thread")
		go loadThread(board, id)
		<-ticker.C
	}
}
開發者ID:soner89,項目名稱:chanloader,代碼行數:15,代碼來源:chanloader.go

示例11: run

// Run the program and return exit code.
func run() int {
	flag.Usage = usageLong // make "-h" work similarly to "help"

	if err := config(); err != nil {
		errf("%s\n", err)
		return 1
	}

	switch cmd := flag.Arg(0); cmd {
	case "download":
		return cmdDownload()
	case "init":
		return cmdInit()
	case "up", "start", "boot", "resume":
		return cmdUp()
	case "save", "suspend":
		return cmdSave()
	case "down", "halt", "stop":
		return cmdStop()
	case "poweroff":
		return cmdPoweroff()
	case "restart":
		return cmdRestart()
	case "reset":
		return cmdReset()
	case "delete":
		return cmdDelete()
	case "info":
		return cmdInfo()
	case "status":
		return cmdStatus()
	case "ssh":
		return cmdSSH()
	case "version":
		outf("Client version: %s\nGit commit: %s\n", Version, GitSHA)
		return 0
	case "help":
		flag.Usage()
		return 0
	case "":
		usageShort()
		return 0
	default:
		errf("Unknown command %q\n", cmd)
		usageShort()
		return 1
	}
}
開發者ID:polvi,項目名稱:boot2docker-cli,代碼行數:49,代碼來源:main.go

示例12: main

func main() {
	pflag.Usage = func() {
		fmt.Fprintln(os.Stderr, "Usage: hipcat [-r room] [message]")
	}

	cfg := Config{}
	err := cfg.Load()
	if err != nil {
		log.Fatalf("Failed to load config: %v", err)
	}
	cfg.bindFlags()
	pflag.Parse()

	if cfg.Room == "" {
		log.Println("Could not find a Room in HIPCAT_ROOM, /etc/hipcat.conf, /.hipcat.conf, ./hipcat.conf or passed with -r")
		pflag.Usage()
		os.Exit(1)
	}
	// was there a message on the command line? If so use it.
	args := pflag.Args()
	if len(args) > 0 {
		msg := RoomMessage{
			Message: strings.Join(args, " "),
		}

		err = msg.Post(&cfg)
		if err != nil {
			log.Fatalf("Post failed: %v", err)
		}
		return
	}

	// ...Otherwise scan stdin
	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		msg := RoomMessage{
			Message: scanner.Text(),
		}

		err = msg.Post(&cfg)
		if err != nil {
			log.Fatalf("Post failed: %v", err)
		}
	}
	if err = scanner.Err(); err != nil {
		log.Fatalf("Error reading: %v", err)
	}
}
開發者ID:jburnham,項目名稱:hipcat,代碼行數:48,代碼來源:hipcat.go

示例13: helpHandle

func helpHandle(args []string) {
	arg := args[0]

	var cmd *Command
	for _, c := range commands {
		if c.Str == arg {
			cmd = &c
			break
		}
	}
	if arg == "" || cmd == nil {
		pflag.Usage()
		return
	}
	cmd.PrintUsage()
}
開發者ID:LA3QMA,項目名稱:wl2k-go,代碼行數:16,代碼來源:main.go

示例14: setup

// Initial setup when the program starts.
func setup() {
	// ensure that zpool/zfs commands do not use localized messages:
	os.Setenv("LC_ALL", "C")

	// command line flags:
	pflag.StringVarP(&cfgFile, "conf", "c", CFGFILE, "configuration file path")
	pflag.BoolVarP(&optDebug, "debug", "d", false, "print debug information to stdout")
	optHashPassword := pflag.BoolP("passwordhash", "P", false, "hash web password")
	optTest := pflag.BoolP("test", "t", false, "test configuration and exit")
	optVersion := pflag.BoolP("version", "v", false, "print version information and exit")

	pflag.Parse()

	if pflag.NArg() > 0 {
		pflag.Usage()
		os.Exit(2)
	}
	if *optVersion {
		version()
		os.Exit(0)
	}
	if *optHashPassword {
		wwwHashPassword()
		os.Exit(0)
	}

	// initialize logging & notification:

	if *optTest {
		optDebug = true
	}

	cfg = getCfg()
	if cfg == nil {
		os.Exit(2)
	}
	notify = setupLog(cfg)

	if *optTest {
		notifyCloseC := notify.Close()
		select { // wait max 1 second for loggers to finish
		case <-notifyCloseC:
		case <-time.After(time.Second):
		}
		os.Exit(0)
	}
}
開發者ID:0987363,項目名稱:zfswatcher,代碼行數:48,代碼來源:setup.go

示例15: init

func init() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: dockdash [options]\n\n")
		flag.PrintDefaults()
	}

	flag.Parse()

	if *helpFlag {
		flag.Usage()
		os.Exit(1)
	}
	if *versionFlag {
		fmt.Println(VERSION)
		os.Exit(0)
	}
}
開發者ID:byrnedo,項目名稱:dockdash,代碼行數:17,代碼來源:main.go


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