本文整理匯總了Golang中flag.Arg函數的典型用法代碼示例。如果您正苦於以下問題:Golang Arg函數的具體用法?Golang Arg怎麽用?Golang Arg使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Arg函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
flag.Parse()
if email == "" || password == "" {
fmt.Println("Invalid E-Mail or Password\n")
flag.Usage()
os.Exit(-1)
}
if flag.NArg()%2 == 0 {
flag.Usage()
os.Exit(-1)
}
imsi := flag.Arg(0)
tags := make([]map[string]string, (flag.NArg()-1)/2)
idx := 0
for i := 1; i < flag.NArg(); i += 2 {
k := flag.Arg(i)
v := flag.Arg(i + 1)
tag := map[string]string{"tagName": k, "tagValue": v}
tags[idx] = tag
idx++
}
fmt.Println(tags)
c, err := goracom.NewClient(email, password)
errToExit(err)
s := c.NewSubscriber()
sub, err := s.Tags(imsi, tags)
errToExit(err)
printSubscriber(*sub)
}
示例2: main
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
latencies := flag.Bool("latencies", false, "record operation latencies.")
flag.Parse()
if flag.NArg() < 2 {
fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
os.Exit(2)
}
var fs fuse.NodeFileSystem
fs, err := zipfs.NewArchiveFileSystem(flag.Arg(1))
if err != nil {
fmt.Fprintf(os.Stderr, "NewArchiveFileSystem failed: %v\n", err)
os.Exit(1)
}
state, _, err := fuse.MountNodeFileSystem(flag.Arg(0), fs, nil)
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
}
state.SetRecordStatistics(*latencies)
state.Debug = *debug
state.Loop()
}
示例3: main
func main() {
var acctAlias = flag.String("a", "", "Account alias to use")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <HW Group UUID>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(1)
}
client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
if err != nil {
exit.Fatal(err.Error())
} else if err := client.Logon("", ""); err != nil {
exit.Fatalf("Login failed: %s", err)
}
reqId, err := client.ArchiveHardwareGroup(flag.Arg(0), *acctAlias)
if err != nil {
exit.Fatalf("Failed to archive Hardware Group %s: %s", flag.Arg(0), err)
}
fmt.Println("Request ID for group archival:", reqId)
}
示例4: main
func main() {
flag.Parse()
if email == "" || password == "" {
fmt.Println("Invalid E-Mail or Password\n")
flag.Usage()
os.Exit(-1)
}
if flag.NArg() != 2 {
flag.Usage()
os.Exit(-1)
}
imsi := flag.Arg(0)
speed := flag.Arg(1)
c, err := goracom.NewClient(email, password)
errToExit(err)
s := c.NewSubscriber()
if sub, err := s.UpdateSpeedClass(imsi, speed); err == nil {
printSubscriber(*sub)
} else {
errToExit(err)
}
}
示例5: main
func main() {
flag.Parse()
root := flag.Arg(0)
bucket = flag.Arg(1)
conf = flag.Arg(2)
filepath.Walk(root, walkpath)
}
示例6: main
func main() {
var versionFlg bool
flag.BoolVar(&versionFlg, "v", false, "show version")
flag.Parse()
if versionFlg {
fmt.Println("openstack-ssh version:", Version)
return
}
if flag.Arg(0) == "" {
panic("please input username")
}
config, err := app.LoadConfig()
if err != nil {
app.ERR(err)
panic(err)
}
key, err := app.FetchPublicKey(flag.Arg(0), config)
if err != nil {
app.ERR(err)
panic(err)
}
fmt.Println(key.PublicKey)
}
示例7: Project
func Project() (err error) {
path, err := os.Getwd()
if err != nil {
err = &FileError{
errors.Wrapf(err, "cmd: Failed to get working directory"),
}
return
}
proj := &project.Project{
Root: path,
}
err = proj.Init()
if err != nil {
return
}
cmd := flag.Arg(1)
switch cmd {
case "init":
err = proj.InitProject()
case "build":
err = proj.Build(flag.Arg(2))
case "repo":
err = proj.Repo(flag.Arg(2))
default:
err = &UnknownCommand{
errors.Newf("cmd: Unknown cmd '%s'", cmd),
}
}
return
}
示例8: main
func main() {
flag.Parse()
if email == "" || password == "" {
fmt.Println("Invalid E-Mail or Password\n")
flag.Usage()
os.Exit(-1)
}
if flag.NArg() != 2 {
flag.Usage()
os.Exit(-1)
}
imsi := flag.Arg(0)
tm, err := strconv.ParseInt(flag.Arg(1), 10, 64)
if err != nil {
fmt.Printf("%s\n\n", err.Error())
flag.Usage()
os.Exit(-1)
}
c, err := goracom.NewClient(email, password)
errToExit(err)
s := c.NewSubscriber()
if tm == 0 {
sub, err := s.UnsetExpiryTime(imsi)
errToExit(err)
printSubscriber(*sub)
} else {
sub, err := s.SetExpiryTime(imsi, tm)
errToExit(err)
printSubscriber(*sub)
}
}
示例9: main
func main() {
var pubFile, privFile string
var help, listen, stayOpen bool
flag.BoolVar(&help, "h", false, "display a short usage message")
flag.BoolVar(&stayOpen, "k", false, "keep listening after client disconnects")
flag.BoolVar(&listen, "l", false, "listen for incoming connections")
flag.StringVar(&privFile, "s", "", "path to signature key")
flag.StringVar(&pubFile, "v", "", "path to verification key")
flag.Parse()
if help {
usage()
os.Exit(1)
}
loadID(privFile, pubFile)
defer func() {
if idPriv != nil {
zero(idPriv[:], 0)
}
}()
if listen {
if flag.NArg() != 1 {
fmt.Println("A port is required (and should be the only argument) when listening.")
}
listener(stayOpen, flag.Arg(0))
return
}
if flag.NArg() != 2 {
fmt.Println("An address and port are required (and should be the only arguments).")
}
sender(flag.Arg(0) + ":" + flag.Arg(1))
}
示例10: main
func main() {
start := time.Now()
flag.Parse()
if *version {
fmt.Printf("inspectFile %d.%d.%d\n", Version[0], Version[1], Version[2])
return
}
if *flserve != "" {
fmt.Printf("Startinf server at %s. Use CTRL+C to quit.\n", *flserve)
listen(*flserve)
return
}
if *fltools != "" {
initTools(*fltools)
}
if *dir {
if flag.NArg() != 1 {
fmt.Println("You must pass a directory name!!!")
return
}
inspectdir(flag.Arg(0))
} else if flag.NArg() != 1 {
fmt.Println("You must pass a file name in parameter!!!")
return
} else {
output = inspectfile(flag.Arg(0), nil)
}
//output = inspectsfile("/media/sf_Temp/Benchmark.pptx", output)
fmt.Printf("Output: %s \n", output)
fmt.Printf("ToolsVersion: %s\n", ExportToolsVersion())
fmt.Printf("Took %v to run.\n", time.Since(start))
}
示例11: main
func main() {
var acctAlias = flag.String("a", "", "Account alias to use")
var snapName = flag.String("s", "", "The name of the Snapshot to delete")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "usage: %s [options] <server-name>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() != 1 || *snapName == "" {
flag.Usage()
os.Exit(1)
}
client, err := clcv1.NewClient(log.New(os.Stdout, "", log.LstdFlags|log.Ltime))
if err != nil {
exit.Fatal(err.Error())
} else if err := client.Logon("", ""); err != nil {
exit.Fatalf("Login failed: %s", err)
}
err = client.DeleteSnapshot(*snapName, flag.Arg(0), *acctAlias)
if err != nil {
exit.Fatalf("Failed to delete snapshot on %s: %s", flag.Arg(0), err)
}
fmt.Printf("Successfully deleted snapshot %q from %s.\n", *snapName, flag.Arg(0))
}
示例12: main
func main() {
log.Trace("-m-", "Opening input file")
// Parse debug flags
flag.BoolVar(&log.LOG_TOKENS, "log-tokens", false, "Enable list of parsed tokens")
flag.BoolVar(&log.LOG_TRACE, "log-trace", false, "Enable trace logging of debug output")
flag.BoolVar(&log.EXTENSIONS, "extensions", false, "Enables parser extensions for additional features. See README for a list of these.")
flag.Parse()
// Init builtin functions
ast.InitBuiltins()
// Parse command line arguments
var file *os.File
var err error
if flag.NArg() == 0 {
log.Trace("-m-", "Reading from stdin")
file = os.Stdin
} else if flag.NArg() == 1 {
log.Trace("-m-", "Reading from file "+flag.Arg(0))
file, err = os.Open(flag.Arg(0))
} else {
panic("Must provide filename to read from or no filename at all")
}
if err != nil {
panic("File name provided does not exist")
}
log.Trace("-m-", "Beginning lex")
yyParse(NewLexer(file))
}
示例13: main
func main() {
flag.Parse()
if flag.NArg() != 2 {
topic = "many"
payload = proto.BytesPayload([]byte("hello"))
} else {
topic = flag.Arg(0)
payload = proto.BytesPayload([]byte(flag.Arg(1)))
}
if *conns == 0 {
*conns = -1
}
i := 0
for {
go client(i)
i++
*conns--
if *conns == 0 {
break
}
time.Sleep(time.Duration(*wait) * time.Millisecond)
}
// sleep forever
<-make(chan struct{})
}
示例14: getFileHandles
// getFileHandles uses our arguments to set up our input and output files
func getFileHandles() (in, out *os.File, err error) {
// Input file should be our only command line argument
if len(flag.Args()) != 1 {
err = fmt.Errorf("Must have exactly one argument (input filename). Received: %v",
flag.Args())
return
}
in, err = os.Open(flag.Arg(0))
if err != nil {
err = fmt.Errorf("Error: Unable to open input file %v: %v", flag.Arg(0),
err)
return
}
// Output file
out = os.Stdout
if *output != "-" {
out, err = os.Create(*output)
if err != nil {
err = fmt.Errorf("Error: Unable to open output file %v: %v", *output,
err)
return
}
}
return
}
示例15: main
func main() {
search := flag.String("s", "", "search issues")
create := flag.Bool("C", false, "create issue")
comment := flag.Bool("c", false, "show comments")
flag.Usage = func() {
fmt.Fprint(os.Stderr, "Usage: goissue [-c ID | -s WORD]\n")
flag.PrintDefaults()
}
flag.Parse()
if flag.NArg() > 1 {
flag.Usage()
os.Exit(1)
}
config := getConfig()
auth := authLogin(config)
if *create {
createIssue(auth)
} else if len(*search) > 0 {
searchIssues(auth, *search)
} else if flag.NArg() == 0 {
showIssues(auth)
} else {
for i := 0; i < flag.NArg(); i++ {
showIssue(auth, flag.Arg(i))
if *comment {
showComments(auth, flag.Arg(i))
}
}
}
}