本文整理匯總了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)
}
}
示例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)
}
示例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))
}
}
示例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
}
}
示例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
}
示例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)
}
}
}
}
}
示例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")
}
}
示例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
}
示例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)
}
示例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 + "]")
}
}
示例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)
}
示例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))
}
示例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()
}
}
示例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,
}))
}
示例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
}
}