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


Golang pflag.Args函數代碼示例

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


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

示例1: main

func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		year := int(time.Now().Year())
		month := int(time.Now().Month())
		calendar(month, year)
	} else if len(flag.Args()) == 1 {
		year, err := strconv.Atoi(flag.Arg(0))
		if err != nil {
			log.Fatal(err)
		}
		for month := 1; month <= 12; month++ {
			calendar(month, year)
			fmt.Println()
		}
	} else if len(flag.Args()) == 2 {
		month, err := strconv.Atoi(flag.Arg(0))
		if err != nil {
			log.Fatal(err)
		}
		year, err := strconv.Atoi(flag.Arg(1))
		if err != nil {
			log.Fatal(err)
		}
		calendar(month, year)
	}
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:27,代碼來源:cal.go

示例2: main

func main() {
	flag.Parse()

	switch {
	case *multiple != "":
		// ugly things about to happen...
		if flag.NArg() > 0 { // means it's using -a
			fmt.Print(performBasename(*multiple, *suffix, *zero)) // pick first from -a

			for _, v := range flag.Args() { // the rest...
				fmt.Print(performBasename(v, *suffix, *zero))
			}

		} else { // means it's using --multiple, split em all
			for _, v := range strings.Split(*multiple, " ") {
				fmt.Print(performBasename(v, *suffix, *zero))
			}
		}
	case *suffix != "": //implies -a
		fmt.Print(performBasename(flag.Args()[0], *suffix, *zero))
	default:
		name := flag.Args()[0]
		suffix := ""
		if flag.NArg() == 2 {
			suffix = flag.Args()[1]
		}
		fmt.Print(performBasename(name, suffix, *zero))
	}

}
開發者ID:postfix,項目名稱:go-coreutils,代碼行數:30,代碼來源:basename.go

示例3: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s", Version)
		os.Exit(0)
	}

	if *unset != "" {
		os.Unsetenv(*unset)
	}

	cmd := new(exec.Cmd)
	cmd.Env = env

	// Check for "-" as an argument, because it means the same as "-i"
	if flag.Arg(0) == "-" {
		cmd.Env = make([]string, 0)
	}

	for i, arg := range flag.Args() {
		if strings.Index(arg, delim) > 0 {
			cmd.Env = append(cmd.Env, arg)
		} else if arg != "-" {
			if *nullEol {
				fatal.Fatalln("cannot specify --null (-0) with command")
			}

			cmd.Path = arg

			cmd.Args = append(cmd.Args, flag.Args()[i:]...)
			cmd.Stdin = os.Stdin
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr

			err := execvp(cmd)
			if err != nil {
				fatal.Fatalln(err)
			}
			return
		}

		i++
	}

	eol := '\n'
	if *nullEol {
		eol = '\x00'
	}

	for _, e := range env {
		fmt.Printf("%s%c", e, eol)
	}

	return
}
開發者ID:postfix,項目名稱:go-coreutils,代碼行數:60,代碼來源:env.go

示例4: 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

示例5: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	}

	if len(flag.Args()) > 0 {
		for i := 0; i < len(flag.Args()); i++ {
			filename := flag.Arg(i)
			_, err := os.Stat(filename)
			if err == nil {
				now := time.Now()
				os.Chtimes(filename, now, now)
			} else if !(*nocreate) {
				f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0644)
				f.Close()
				if err != nil {
					log.Fatal(err)
				}
			}
		}
	}
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:29,代碼來源:touch.go

示例6: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	switch {
	case *version:
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	case *wrap < 0:
		log.Fatalf("invalid wrap size: %d", *wrap)
	default:
		if len(flag.Args()) == 0 {
			readAndHandle(os.Stdin, decode, ignore, wrap)
		} else {
			for i := 0; i < len(flag.Args()); i++ {
				file, err := os.Open(flag.Args()[i])
				if err != nil {
					log.Fatal(err)
				}
				readAndHandle(file, decode, ignore, wrap)
			}
		}
	}

}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:28,代碼來源:base64.go

示例7: check_md5sum

/*
   check the md5sum for all of files from cmdline
*/
func check_md5sum() bool {
	if len(flag.Args()) == 0 ||
		(len(flag.Args()) == 1 && flag.Args()[0] == "-") {

		/* Known Issue:
		   Ctrl+Z on cmd can not trigger io.EOF */
		return check_md5sum_f(os.Stdin)
	}

	has_err := false

	for i := 0; i < len(flag.Args()); i++ {
		//output_e("use file: %s\n", flag.Args()[i])
		file, err := os.Open(flag.Args()[i])
		if err != nil {
			output_e("md5sum: %s\n", err.Error())
			has_err = true
			continue
		}
		if b := check_md5sum_f(file); !b {
			has_err = true
		}
		file.Close()
	}

	return !has_err
}
開發者ID:fangdingjun,項目名稱:go-coreutils,代碼行數:30,代碼來源:check_sum.go

示例8: main

func main() {
	flag.Parse()
	if len(flag.Args()) == 0 {
		log.Fatal("need query")
	}
	args := flag.Args()
	if !*retweets {
		args = append(args, "-rt")
	}
	search := url.QueryEscape(strings.Join(args, " "))
	query := fmt.Sprintf("%s?q=%s&count=%d", twSearchBase, search, *resnum)
	for {
		tw, err := twitquery(query)
		if err != nil {
			log.Fatal(err)
		}
		r := tw.Statuses
		for i := range r {
			if *reverse {
				fmt.Println(r[i])
			} else {
				fmt.Println(r[len(r)-i-1])
			}
		}
		if !*follow { // if not in follow mode we are done
			break
		}
		query = twSearchBase + tw.Meta.RefreshUrl
		time.Sleep(*followDelay)
	}
}
開發者ID:imarko,項目名稱:tgrep,代碼行數:31,代碼來源:tgrep.go

示例9: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	switch {
	case *version:
		fmt.Fprintf(os.Stdout, "%s", Version)
		os.Exit(0)
	case *multiple:
		for _, v := range flag.Args() {
			dir := baseName(v, *suffix, *zero)
			fmt.Print(dir)
		}
	case *suffix != "":
		// Implies --multiple/-a
		for _, v := range flag.Args() {
			dir := baseName(v, *suffix, *zero)
			fmt.Print(dir)
		}
	default:
		dir := baseName(flag.Args()[0], *suffix, *zero)
		fmt.Print(dir)
	}
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:27,代碼來源:basename.go

示例10: parseFlags

func parseFlags() (*cmdConfig, *busltee.Config, error) {
	publisherConf := &busltee.Config{}
	cmdConf := &cmdConfig{}

	cmdConf.RollbarEnvironment = os.Getenv("ROLLBAR_ENVIRONMENT")
	cmdConf.RollbarToken = os.Getenv("ROLLBAR_TOKEN")

	// Connection related flags
	flag.BoolVarP(&publisherConf.Insecure, "insecure", "k", false, "allows insecure SSL connections")
	flag.IntVar(&publisherConf.Retry, "retry", 5, "max retries for connect timeout errors")
	flag.IntVar(&publisherConf.StreamRetry, "stream-retry", 60, "max retries for streamer disconnections")
	flag.Float64Var(&publisherConf.Timeout, "connect-timeout", 1, "max number of seconds to connect to busl URL")

	// Logging related flags
	flag.StringVar(&publisherConf.LogPrefix, "log-prefix", "", "log prefix")
	flag.StringVar(&publisherConf.LogFile, "log-file", "", "log file")
	flag.StringVar(&publisherConf.RequestID, "request-id", "", "request id")

	if flag.Parse(); len(flag.Args()) < 2 {
		return nil, nil, errors.New("insufficient args")
	}

	publisherConf.URL = flag.Arg(0)
	publisherConf.Args = flag.Args()[1:]

	return cmdConf, publisherConf, nil
}
開發者ID:heroku,項目名稱:busl,代碼行數:27,代碼來源:main.go

示例11: parseArgs

// The following command `remotectl -profile test.sh -list` would result in
// len(args) <= i returning false.
func parseArgs(args []string) (query, cmd string) {
	i := flag.NFlag() + 1

	cmd = strings.Join(flag.Args(), " ")

	if len(args) > i && args[i] != "--" {
		query = flag.Args()[0]
		cmd = strings.Join(flag.Args()[1:], " ")
	}

	return query, cmd
}
開發者ID:simplexlab,項目名稱:remotectl,代碼行數:14,代碼來源:main.go

示例12: main

func main() {
	verbose := flag.BoolP("verbose", "v", false, "Verbose mode")
	flag.Parse()

	logger = initLogger(*verbose)

	switch {
	case len(flag.Args()) == 0:
		Serve()
	case len(flag.Args()) >= 1:
		RunCommand(flag.Arg(0), flag.Args()[1:])
	default:
		printUsage()
		os.Exit(2)
	}
}
開發者ID:brandur,項目名稱:heroku-agent,代碼行數:16,代碼來源:main.go

示例13: ParseCommand

// Parse the command from the command line
func ParseCommand() (*Command, []string) {
	args := pflag.Args()
	if len(args) < 1 {
		fatal("No command supplied\n")
	}

	cmd := strings.ToLower(args[0])
	args = args[1:]

	// Find the command doing a prefix match
	var command *Command
	for i := range Commands {
		trialCommand := &Commands[i]
		// exact command name found - use that
		if trialCommand.Name == cmd {
			command = trialCommand
			break
		} else if strings.HasPrefix(trialCommand.Name, cmd) {
			if command != nil {
				fs.Stats.Error()
				log.Fatalf("Not unique - matches multiple commands %q", cmd)
			}
			command = trialCommand
		}
	}
	if command == nil {
		fs.Stats.Error()
		log.Fatalf("Unknown command %q", cmd)
	}
	if command.Run == nil {
		syntaxError()
	}
	command.checkArgs(args)
	return command, args
}
開發者ID:shimondoodkin,項目名稱:rclone,代碼行數:36,代碼來源:rclone.go

示例14: main

func main() {
	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

	if *version {
		fmt.Printf("%s\n", Version)
		os.Exit(0)
	}

	args := flag.Args()
	if flag.NArg() == 0 {
		args = []string{"y"}
	}

	for {
		for i, arg := range args {
			os.Stdout.WriteString(arg)

			if i == len(args)-1 {
				os.Stdout.Write(LineFeed)
			} else {
				os.Stdout.Write(Space)
			}
		}
	}
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:29,代碼來源:yes.go

示例15: parseArgs

func parseArgs() args {
	result := args{}
	pflag.Usage = usage
	pflag.BoolVarP(&result.options.KeepGoing, "keep-going", "k", false, "")
	pflag.BoolVar(&result.options.CheckAll, "check-all", false, "")
	pflag.StringVarP(&result.scriptFile, "file", "f", "", "")
	verbose := pflag.BoolP("verbose", "v", false, "")
	quiet := pflag.BoolP("quiet", "q", false, "")
	topics := pflag.String("debug", "", "")
	pflag.Parse()
	if *topics != "" {
		result.debugTopics = strings.Split(*topics, ",")
	}

	// argh: really, we just want a callback for each occurence of -q
	// or -v, which decrements or increments verbosity
	if *quiet {
		result.verbosity = 0
	} else if *verbose {
		result.verbosity = 2
	} else {
		result.verbosity = 1
	}

	result.options.Targets = pflag.Args()
	return result
}
開發者ID:sbinet,項目名稱:fubsy,代碼行數:27,代碼來源:fubsy.go


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