本文整理汇总了Golang中flag.NArg函数的典型用法代码示例。如果您正苦于以下问题:Golang NArg函数的具体用法?Golang NArg怎么用?Golang NArg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NArg函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
if flag.NArg() < 1 {
fmt.Println("Must specify path to a gouchstore compatible file")
return
} else if flag.NArg() < 2 {
fmt.Println("Must specify path to the new compacted gouchstore file")
return
}
var ops gouchstore.GouchOps
if *memCompact {
ops = gouchstore.NewMemCompactGouchOps()
} else {
ops = gouchstore.NewBaseGouchOps()
}
db, err := gouchstore.OpenEx(flag.Args()[0], gouchstore.OPEN_RDONLY, ops)
if err != nil {
fmt.Println(err)
return
}
defer db.Close()
err = db.Compact(flag.Arg(1))
if err != nil {
fmt.Println(err)
}
}
开发者ID:ngaut,项目名称:gouchstore,代码行数:30,代码来源:main.go
示例2: main
func main() {
FILE = os.Stdin
flag.Parse()
versionTxt()
sigChan := make(chan int, 0)
d0 := make(chan chanT, 0)
d1 := make(chan chanT, 0)
c := make(chan string, 30)
f := make(chan io.Reader, 5)
setupSignal(sigChan)
go pr(c, d0)
// As soon as you introduce more than one file, your output
// will get mixed up. How do you fix that?
for i := 0; i < flag.NArg(); i++ {
FILE, _ = Open(flag.Arg(i))
f <- FILE
go read(f, c, d1)
}
if flag.NArg() == 0 {
f <- FILE
go read(f, c, d1)
}
wait(d0, d1, sigChan, flag.NArg())
}
开发者ID:mchirico,项目名称:chirico,代码行数:32,代码来源:main.go
示例3: main
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
var opt optionSet
flag.BoolVar(&opt.v, "V", false, "show version.")
flag.BoolVar(&opt.g, "g", false, "enable grep.")
flag.BoolVar(&opt.search_binary, "search-binary", false, "search binary files for matches on grep enable.")
flag.BoolVar(&opt.grep_only, "grep-only", false, "enable grep and disable file search.")
flag.StringVar(&opt.ignore, "ignore", "", "pattern is ignored.")
flag.BoolVar(&opt.hidden, "hidden", false, "search hidden files.")
flag.BoolVar(&opt.ignorecase, "ignorecase", false, "ignore case distinctions in pattern.")
flag.Parse()
if opt.v {
fmt.Printf("version: %s\n", version)
os.Exit(0)
}
if flag.NArg() < 1 {
usage()
}
pattern := flag.Arg(0)
fpath := "."
if flag.NArg() >= 2 {
fpath = strings.TrimRight(flag.Arg(1), separator)
}
g := newGorep(pattern, &opt)
chans := g.kick(fpath)
g.report(chans, verifyColor())
}
开发者ID:ryochack,项目名称:gorep,代码行数:32,代码来源:gorep.go
示例4: 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
示例5: 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
示例6: 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
示例7: 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
示例8: main
func main() {
if flag.NArg() == 0 {
fmt.Printf("[Error] path or file must provide one.\n\n")
flag.Usage()
os.Exit(retFail)
}
for i := 0; i < flag.NArg(); i++ {
path := strings.TrimSpace(flag.Arg(i))
switch dir, err := os.Stat(path); {
case err != nil:
//fmt.Printf("[Error] error in Stat(): %s.\n", err)
panic(err)
case dir.IsDir():
if path, err = filepath.Abs(path); err != nil {
panic(err)
}
dealDirWithWhiteList(path, cmd, suffixArray)
default:
if path, err = filepath.Abs(path); err != nil {
panic(err)
}
dealFileWithWhiteList(path, cmd, suffixArray)
}
}
}
开发者ID:soarpenguin,项目名称:go-scripts,代码行数:27,代码来源:rm_end_space.go
示例9: main
func main() {
help := flag.Bool("help", false, help_text)
version := flag.Bool("version", false, version_text)
flag.Parse()
if *help {
fmt.Println(help)
os.Exit(0)
}
if *version {
fmt.Println(version_text)
os.Exit(0)
}
if flag.NArg() > 0 {
fmt.Println(help)
os.Exit(0)
}
if flag.NArg() == 0 && flag.NFlag() == 0 {
var username string
err := GetCurrentUser(&username)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
fmt.Println(username)
}
}
开发者ID:ProhtMeyhet,项目名称:go-coreutils,代码行数:35,代码来源:logname.go
示例10: convertCmd
func convertCmd() {
if flag.NArg() != 2 && flag.NArg() != 3 {
log.Fatal("Error: wrong number of arguments (expected input and output files)")
}
// should refactor this to open both files first, then do processing? not
// sure what best practice is.
inFname := flag.Arg(1)
outFname := flag.Arg(2)
bm, b := loadIn(inFname)
if b == nil {
log.Fatal("null bom")
}
if *inFormat == "csv" && bm == nil {
// TODO: from inname? if ShortName?
bm = &BomMeta{Name: "untitled",
Owner: anonUser.name}
b.Version = "unversioned"
}
b.Created = time.Now()
b.Progeny = "File import from " + inFname + " (" + *inFormat + ")"
if err := bm.Validate(); err != nil {
log.Fatal("loaded bommeta not valid: " + err.Error())
}
if err := b.Validate(); err != nil {
log.Fatal("loaded bom not valid: " + err.Error())
}
dumpOut(outFname, bm, b)
}
开发者ID:bnewbold,项目名称:bommom,代码行数:35,代码来源:bommom.go
示例11: listCmd
func listCmd() {
openBomStore()
var bomMetas []BomMeta
var err error
if flag.NArg() > 2 {
log.Fatal("Error: too many arguments...")
}
if flag.NArg() == 2 {
name := flag.Arg(1)
if !isShortName(name) {
log.Fatal("Error: not a possible username: " + name)
}
bomMetas, err = bomstore.ListBoms(ShortName(name))
if err != nil {
log.Fatal(err)
}
} else {
// list all boms from all names
bomMetas, err = bomstore.ListBoms("")
if err != nil {
log.Fatal(err)
}
}
for _, bm := range bomMetas {
fmt.Println(bm.Owner + "/" + bm.Name)
}
}
开发者ID:bnewbold,项目名称:bommom,代码行数:28,代码来源:bommom.go
示例12: dumpCmd
func dumpCmd() {
if flag.NArg() != 3 && flag.NArg() != 4 {
log.Fatal("Error: wrong number of arguments (expected user and BOM name, optional file)")
}
userStr := flag.Arg(1)
nameStr := flag.Arg(2)
if !isShortName(userStr) || !isShortName(nameStr) {
log.Fatal("Error: not valid ShortName: " + userStr +
" and/or " + nameStr)
}
var fname string
if flag.NArg() == 4 {
fname = flag.Arg(3)
} else {
fname = ""
}
openBomStore()
openAuthStore()
bm, b, err := bomstore.GetHead(ShortName(userStr), ShortName(nameStr))
if err != nil {
log.Fatal(err)
}
dumpOut(fname, bm, b)
}
开发者ID:bnewbold,项目名称:bommom,代码行数:30,代码来源:bommom.go
示例13: main
func main() {
var dockerAddr string
var transferAddr string
var debug bool
flag.BoolVar(&debug, "DEBUG", false, "enable debug")
flag.StringVar(&dockerAddr, "d", "tcp://192.168.99.100:2376", "docker daemon addr")
flag.StringVar(&transferAddr, "t", "10.200.8.37:8433", "transfer addr")
flag.Parse()
if flag.NArg() < 1 {
fmt.Println("need at least one container id")
return
}
if debug {
log.SetLevel(log.DebugLevel)
}
cli, _ := client.NewEnvClient()
metric.SetGlobalSetting(cli, 2, 3, "vnbe", "eth0")
client := statsd.CreateStatsDClient(transferAddr)
ctx := context.Background()
for i := 0; i < flag.NArg(); i++ {
if c, err := cli.ContainerInspect(ctx, flag.Arg(i)); err != nil {
fmt.Println(flag.Arg(i), err)
continue
} else {
go start_watcher(client, c.ID, c.State.Pid)
}
}
for {
}
}
开发者ID:projecteru,项目名称:eru-metric,代码行数:33,代码来源:example_statsd.go
示例14: main
func main() {
outFilename := flag.String("o", "", `output file`)
yyExtraName = flag.String("yyextra", "", "Data type stored in yyextra (use an empty string for no yyextra)")
standalone = flag.Bool("s", false, `standalone code; NN_FUN macro substitution, no Lex() method`)
customError = flag.Bool("e", false, `custom error func; no Error() method`)
autorun = flag.Bool("r", false, `run generated program`)
nfadotFile := flag.String("nfadot", "", `show NFA graph in DOT format`)
dfadotFile := flag.String("dfadot", "", `show DFA graph in DOT format`)
flag.Parse()
nfadot = createDotFile(*nfadotFile)
dfadot = createDotFile(*dfadotFile)
defer func() {
if nfadot != nil {
dieErr(nfadot.Close(), "Close")
}
if dfadot != nil {
dieErr(dfadot.Close(), "Close")
}
}()
infile, outfile := os.Stdin, os.Stdout
var err error
if flag.NArg() > 0 {
dieIf(flag.NArg() > 1, "nex: extraneous arguments after", flag.Arg(0))
dieIf(strings.HasSuffix(flag.Arg(0), ".go"), "nex: input filename ends with .go:", flag.Arg(0))
basename := flag.Arg(0)
n := strings.LastIndex(basename, ".")
if n >= 0 {
basename = basename[:n]
}
infile, err = os.Open(flag.Arg(0))
dieErr(err, "nex")
defer infile.Close()
if !*autorun {
if *outFilename == "" {
outfile, err = os.Create(basename + ".nn.go")
} else {
outfile, err = os.Create(*outFilename)
}
dieErr(err, "nex")
defer outfile.Close()
}
}
if *autorun {
tmpdir, err := ioutil.TempDir("", "nex")
dieIf(err != nil, "tempdir:", err)
defer func() {
dieErr(os.RemoveAll(tmpdir), "RemoveAll")
}()
outfile, err = os.Create(tmpdir + "/lets.go")
dieErr(err, "nex")
defer outfile.Close()
}
process(outfile, infile)
if *autorun {
c := exec.Command("go", "run", outfile.Name())
c.Stdin, c.Stdout, c.Stderr = os.Stdin, os.Stdout, os.Stderr
dieErr(c.Run(), "go run")
}
}
开发者ID:robertkluin-wf,项目名称:nex,代码行数:60,代码来源:nex.go
示例15: main
func main() {
flag.Usage = printUsage
flag.Parse()
if flag.NArg() != 1 {
printUsage()
os.Exit(2)
}
clientName := fmt.Sprintf("%s:%d", *subHostname, *subPortNum)
client, err := rpc.DialHTTP("tcp", clientName)
if err != nil {
fmt.Fprintf(os.Stderr, "Error dialing\t%s\n", err)
os.Exit(1)
}
for _, subcommand := range subcommands {
if flag.Arg(0) == subcommand.command {
if flag.NArg()-1 != subcommand.numArgs {
printUsage()
os.Exit(2)
}
subcommand.cmdFunc(client, flag.Args()[1:])
os.Exit(3)
}
}
printUsage()
os.Exit(2)
}
开发者ID:JohnTheodore,项目名称:Dominator,代码行数:26,代码来源:main.go
示例16: main
func main() {
flag.Usage = usage
flag.Parse()
if *tabwidth < 0 {
fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabwidth)
os.Exit(2)
}
if flag.NArg() == 0 {
if err := processFile("/dev/stdin"); err != nil {
report(err)
}
}
for i := 0; i < flag.NArg(); i++ {
path := flag.Arg(i)
switch dir, err := os.Stat(path); {
case err != nil:
report(err)
case dir.IsRegular():
if err := processFile(path); err != nil {
report(err)
}
case dir.IsDirectory():
walkDir(path)
}
}
os.Exit(exitCode)
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:30,代码来源:gofmt.go
示例17: main
func main() {
flag.Usage = usage
flag.Parse()
command := ""
if flag.NArg() > 0 {
command = flag.Arg(0)
switch command {
case "convert":
if flag.NArg() <= 1 {
fmt.Fprintln(os.Stderr, "missing cover profile")
os.Exit(1)
}
if err := convertProfiles(flag.Args()[1:]...); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
case "annotate":
os.Exit(annotateSource())
case "report":
os.Exit(reportCoverage())
case "test":
if err := runTests(flag.Args()[1:]); err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
default:
fmt.Fprintf(os.Stderr, "Unknown command: %#q\n\n", command)
usage()
}
} else {
usage()
}
}
开发者ID:litixsoft,项目名称:lxb,代码行数:34,代码来源:main.go
示例18: main
func main() {
var Loadpagelist = flag.Bool("l", false, "\tLoad the ed2klink page url list")
flag.Parse()
if *Loadpagelist {
listfilename := flag.Arg(0)
m, err := loadvv(listfilename)
if err == nil {
loadlist(m)
} else {
fmt.Printf("File %s not exist.\n", listfilename)
}
} else {
if flag.NArg() > 0 {
m := make(map[int]string)
for p, i := 0, 0; i < flag.NArg(); i++ {
if strings.HasPrefix(flag.Arg(i), "http://") {
m[p] = flag.Arg(i)
p++
}
}
loadlist(m)
} else {
help()
}
}
}
开发者ID:sunclx,项目名称:ed2kcrawler,代码行数:26,代码来源:main.go
示例19: 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
示例20: getCmdLine
func getCmdLine() (result cmdlineT) {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
fmt.Fprintln(os.Stderr,
"\t[options] datadir [cert.pem key.pem]")
flag.PrintDefaults()
}
flag.StringVar(&result.laddr, "listen", ":8000",
"listen address, \":8080\" or \"localhost:5050\"")
flag.BoolVar(&result.tls, "tls", false, "use TLS. "+
"Requires cert.pem and key.pem positional args "+
"(see crypto/tls/generate_cert.go).")
flag.StringVar(&result.singleuser, "singleuser", "",
"Always logged in as specified user, without password")
flag.IntVar(&result.quittimeout, "quittimeout", 1,
"seconds to wait when shutting down")
flag.Parse()
if !result.tls {
if flag.NArg() != 1 {
log.Fatalln("Expecting 1 positional arg, found",
flag.NArg())
}
} else {
if flag.NArg() != 3 {
log.Fatalln("TLS requires 3 positional args, found",
flag.NArg())
}
result.cert = flag.Arg(1)
result.key = flag.Arg(2)
}
result.dir = flag.Arg(0)
return
}
开发者ID:vaibhav2800,项目名称:forge,代码行数:35,代码来源:flag.go
注:本文中的flag.NArg函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论