本文整理匯總了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)
}
}
示例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))
}
}
示例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
}
示例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)
}
}
示例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)
}
}
}
}
}
示例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)
}
}
}
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}
}
示例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
}
示例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)
}
}
}
}
示例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
}