本文整理汇总了Golang中flag.Arg函数的典型用法代码示例。如果您正苦于以下问题:Golang Arg函数的具体用法?Golang Arg怎么用?Golang Arg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Arg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
开发者ID:135yshr,项目名称:goracom,代码行数:32,代码来源:set_tag.go
示例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()
}
开发者ID:CloudLife,项目名称:go-fuse,代码行数:28,代码来源:main.go
示例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)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:28,代码来源:archive.go
示例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)
}
}
开发者ID:135yshr,项目名称:goracom,代码行数:26,代码来源:update_speed.go
示例5: main
func main() {
flag.Parse()
root := flag.Arg(0)
bucket = flag.Arg(1)
conf = flag.Arg(2)
filepath.Walk(root, walkpath)
}
开发者ID:cyarie,项目名称:suchgopcandidatewow.com,代码行数:7,代码来源:uploader.go
示例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)
}
开发者ID:pyama86,项目名称:openstack-ssh,代码行数:28,代码来源:main.go
示例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
}
开发者ID:pacur,项目名称:pacur,代码行数:33,代码来源:project.go
示例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)
}
}
开发者ID:135yshr,项目名称:goracom,代码行数:34,代码来源:expiry_time.go
示例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))
}
开发者ID:jmptrader,项目名称:go-schannel,代码行数:35,代码来源:nc.go
示例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))
}
开发者ID:fdegui15,项目名称:dockerif,代码行数:35,代码来源:inspectsFile.go
示例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))
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:29,代码来源:snapshot_delete.go
示例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))
}
开发者ID:mhoc,项目名称:msp,代码行数:33,代码来源:main.go
示例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{})
}
开发者ID:scozssfork,项目名称:mqtt,代码行数:30,代码来源:main.go
示例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
}
开发者ID:CodeMonk,项目名称:GoSquareToShopify,代码行数:28,代码来源:main.go
示例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))
}
}
}
}
开发者ID:andradeandrey,项目名称:goissue,代码行数:32,代码来源:main.go
示例16: main
func main() {
flag.Parse()
c := client.NewHTTPClient(*address)
if err := c.WaitUntilReady(*waitDuration); err != nil {
log.Fatal(err)
}
serviceMethod, params := flag.Arg(0), json.RawMessage(flag.Arg(1))
if *legacyCall {
var resp json.RawMessage
if err := c.Call(serviceMethod, ¶ms, &resp); err != nil {
log.Fatal(err)
}
fmt.Println(string(resp))
} else {
rd := c.Stream(serviceMethod, ¶ms)
defer rd.Close()
for {
var resp json.RawMessage
if err := rd.NextResult(&resp); err == io.EOF {
break
} else if err != nil {
log.Fatal(err)
}
fmt.Println(string(resp))
}
}
}
开发者ID:linearregression,项目名称:shipshape,代码行数:29,代码来源:example.go
示例17: main
func main() {
flag.Parse()
n, err := strconv.Atoi(flag.Arg(0))
if err != nil {
fmt.Printf("unknown number")
return
}
c, err := strconv.Atoi(flag.Arg(1))
if err != nil {
fmt.Printf("unknown concurrent")
return
}
ch_end := make(chan int, 100)
for i := 0; i < c; i++ {
go goroutine_gosched(n, ch_end)
}
for i := 0; i < c; i++ {
<-ch_end
}
return
}
开发者ID:shell909090,项目名称:context,代码行数:26,代码来源:g_sched.go
示例18: main
func main() {
var acctAlias = flag.String("a", "", "Account alias to use")
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 {
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)
}
credentials, err := client.GetServerCredentials(flag.Arg(0), *acctAlias)
if err != nil {
exit.Fatalf("Failed to obtain the credentials of server %q: %s", flag.Arg(0), err)
}
fmt.Printf("Credentials for %s:\n", flag.Arg(0))
fmt.Printf("User: %s\n", credentials.Username)
fmt.Printf("Password: '%s'\n", credentials.Password)
}
开发者ID:grrtrr,项目名称:clcv1,代码行数:31,代码来源:get_credentials.go
示例19: main
func main() {
flag.Parse()
if flag.NArg() != 1 && flag.NArg() != 2 {
flag.Usage()
fmt.Fprintf(os.Stderr, "Usage: %s <remote> [<local>]\n", os.Args[0])
os.Exit(2)
}
handler := ext.FatalHandler(log15.CallerFileHandler(log15.StderrHandler))
if flagVeryVerbose {
handler = log15.LvlFilterHandler(log15.LvlDebug, handler)
} else if flagVerbose {
handler = log15.LvlFilterHandler(log15.LvlInfo, handler)
}
log15.Root().SetHandler(handler)
local := "."
if flag.NArg() == 2 {
local = flag.Arg(1)
}
m := sftpsync.SyncManager{
Local: local,
Remote: flag.Arg(0),
SkipFiles: skipFiles,
SkipDirs: skipDirs,
Append: flagAppend,
DryRun: flagDryRun,
}
err := m.Run()
if err != nil {
log.Crit("run error", "err", err)
return
}
}
开发者ID:iwat,项目名称:sftpsync,代码行数:35,代码来源:main.go
示例20: main
func main() {
flag.Usage = usage
flag.Parse()
if flag.NArg() != 2 {
flag.Usage()
os.Exit(1)
}
serverAddr := flag.Arg(0)
recordFilename := flag.Arg(1)
recordInput, err := os.Open(recordFilename)
if err != nil {
log.Fatalf("Failed to open record file %q: %v", recordFilename, err)
}
defer recordInput.Close()
conn, err := net.Dial("tcp", serverAddr)
if err != nil {
log.Fatalf("Failed to connect to server %q: %v", serverAddr, err)
}
defer conn.Close()
replayer := record.NewReaderReplayer(recordInput, conn)
// Discard everything the server sends us.
go readAndDiscard(conn)
replayer.Replay()
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:29,代码来源:replay.go
注:本文中的flag.Arg函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论