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


Golang pflag.Arg函數代碼示例

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


在下文中一共展示了Arg函數的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.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s", Help)
		os.Exit(1)
	}
	flag.Parse()

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

	if flag.NArg() > 1 {
		fatal.Fatalf("extra operand %s", flag.Arg(1))
	}

	var (
		file *os.File
		err  error
	)

	if flag.Arg(0) == "-" || flag.NArg() == 0 {
		file = os.Stdin
	} else {
		file, err = os.Open(flag.Arg(0))
		if err != nil {
			fatal.Fatalln(err)
		}
		defer file.Close()
	}

	ok := tsort(file)

	os.Exit(ok)
}
開發者ID:postfix,項目名稱:go-coreutils,代碼行數:35,代碼來源:tsort.go

示例3: main

func main() {
	flag.Usage = func() {
		// This is a little weird because I want to insert the correct
		// UTMP/WTMP file names into the Help output, but usually my
		// Help constants are raw string literals, so I had to
		// break it up into a couple chunks and move around some formatting.
		fmt.Fprintf(os.Stderr, "%s %s.  %s %s",
			Help1, utmp.UtmpFile, utmp.WtmpFile, Help2)
		os.Exit(1)
	}
	flag.Parse()

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

	switch flag.NArg() {
	case 0:
		uptime(utmp.UtmpFile, utmp.CheckPIDs)
	case 1:
		uptime(flag.Arg(0), 0)
	default:
		fatal.Fatalf("extra operand %s\n", flag.Arg(1))
	}
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:26,代碼來源:uptime.go

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

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

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

示例7: main

func main() {
	logmgr.SetOutput(os.Stderr)
	if flagVerbose {
		logmgr.SetLevel(logrus.DebugLevel)
	} else {
		logmgr.SetLevel(logrus.InfoLevel)
	}

	flag.Parse()
	conf := &config.BuildConfig{
		BuildDir:  flagBuildDir,
		OutputDir: flag.Arg(0),
		Platform:  flagPlatform,
		Arch:      flagArch,
	}

	recipes := flag.Args()[1:]

	// Special case - passing a single 'all' means build all binaries.
	if len(recipes) == 1 && recipes[0] == "all" {
		recipes = builder.AllBinaries()
	}

	log.WithField("recipes", recipes).Info("Starting build")
	err := builder.Build(recipes, conf)
	if err != nil {
		log.WithField("err", err).Error("Error building")
	} else {
		log.Info("Successfully built")
	}
}
開發者ID:andrew-d,項目名稱:sbuild,代碼行數:31,代碼來源:main.go

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

示例9: main

func main() {

	var cluster *string = flag.String("cluster", "default", "Name of cluster")

	flag.Parse()

	if flag.NArg() < 2 {
		fmt.Println("Usage:\n\taws-rollout [service] [image]")
		return
	}

	var service string = flag.Arg(0)
	var image string = flag.Arg(1)

	svc := ecs.New(session.New())

	clusterArn, err := findClusterArn(svc, *cluster)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	serviceArn, err := findServiceArn(svc, clusterArn, service)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	taskArn, err := findTaskArn(svc, clusterArn, serviceArn)
	newTaskArn, err := setImage(svc, taskArn, image)
	params := &ecs.UpdateServiceInput{
		Service:        aws.String(serviceArn),
		Cluster:        aws.String(clusterArn),
		TaskDefinition: aws.String(newTaskArn),
	}
	serv, err := svc.UpdateService(params)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	fmt.Printf("Deployed %s %d", newTaskArn, *serv.Service.PendingCount)
}
開發者ID:oberd,項目名稱:aws-rollout,代碼行數:40,代碼來源:aws-rollout.go

示例10: main

func main() {
	flag.Parse() // Scan the arguments list
	fmt.Fprintln(os.Stdout, LOGO)
	if *versionFlag {
		fmt.Println("Version:", APP_VERSION)
		return
	}
	cmd := flag.Arg(0)
	name := flag.Arg(1)
	switch cmd {
	case "help":
		printHelpCommand(nil)
	case "init":
		createNewProject(name)
	case "get":
		getNewImport(name)
	case "run":
		runDevelopmentServer(name)
	default:
		printHelpCommand("Do Not Recognize command: [" + cmd + "]")
	}
}
開發者ID:etgryphon,項目名稱:gaea,代碼行數:22,代碼來源:gaea.go

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

示例12: main

func main() {
	NAME = path.Base(os.Args[0])
	flags := make(map[string]*bool)

	flag.Usage = usageLong
	flags["version"] = flag.BoolP("version", "v", false,
		"Print version number and exit")
	flags["help"] = flag.BoolP("help", "h", false,
		"Print this help message and exit")
	flags["index"] = flag.BoolP("index", "i", false,
		"Create indexes for the lexicon")

	flag.Parse()

	// Handle -v/--version
	if *flags["version"] {
		fmt.Println(Version)
		os.Exit(0)
	}

	// Handle -h/--help
	if *flags["help"] {
		if strings.Contains(strings.Join(os.Args, " "), "--help") {
			usageLong()
		} else {
			usageShort()
		}
		os.Exit(0)
	}

	// Handle -i/--index
	if *flags["index"] {
		fmt.Println("Creating indexes")
		if err := index.Create(); err != nil {
			fmt.Fprintf(os.Stderr, "Error creating indexes: %v", err)
			os.Exit(1)
		} else {
			fmt.Println("Done")
			os.Exit(0)
		}
	}

	// Handle missing <text> argument
	if flag.NArg() == 0 {
		fmt.Fprintf(os.Stderr, "%s: missing <text> argument\n", NAME)
		usageLong()
		os.Exit(1)
	}

	fmt.Printf("Searching for %q\n", flag.Arg(0))
}
開發者ID:maxnordlund,項目名稱:adk,代碼行數:51,代碼來源:konkordans.go

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

示例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)
	}

	if flag.NArg() > 1 {
		fatal.Fatalf("extra operand %s", flag.Arg(1))
	}

	file := os.Stdin
	if (flag.Arg(0) != "-" &&
		flag.Arg(0) != "") ||
		flag.NArg() != 0 {

		var err error
		file, err = os.Open(flag.Arg(0))
		if err != nil {
			fatal.Fatalln(err)
		}
		defer file.Close()
	}

	os.Exit(tsort(struct {
		io.Reader
		io.Writer
	}{
		file,
		os.Stdout,
	}))
}
開發者ID:patrickToca,項目名稱:go-coreutils,代碼行數:37,代碼來源:tsort.go

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


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