本文整理汇总了Golang中github.com/timtadh/getopt.GetOpt函数的典型用法代码示例。如果您正苦于以下问题:Golang GetOpt函数的具体用法?Golang GetOpt怎么用?Golang GetOpt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetOpt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: countReporter
func countReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hf:",
[]string{
"help",
"filename=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
filename := "count"
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-f", "--filename":
filename = oa.Arg()
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
r, err := reporters.NewCount(conf, filename)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v", err)
os.Exit(1)
}
return r, args
}
示例2: main
func main() {
short := "h"
long := []string{
"help",
"allow-dups",
}
args, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
port := -1
dups := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "--allow-dups":
dups = true
}
}
if len(args) != 1 {
fmt.Fprintln(os.Stderr, "You must specify a port")
Usage(ErrorCodes["opts"])
}
port = parse_int(args[0])
fmt.Println("starting")
server := net.NewServer(func() net.Queue { return queue.NewQueue(dups) })
server.Start(port)
}
示例3: uniproxMode
func uniproxMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hw:",
[]string{
"help",
"walks=",
"max",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
walks := 15
max := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
case "-w", "--walks":
walks = cmd.ParseInt(oa.Arg())
case "--max":
max = true
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
miner, err := uniprox.NewWalker(conf, walks, max)
if err != nil {
log.Fatal(err)
}
return miner, args
}
示例4: premuskMode
func premuskMode(argv []string, conf *config.Config) (miners.Miner, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
"teleport=",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
cmd.Usage(cmd.ErrorCodes["opts"])
}
teleport := .01
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
cmd.Usage(0)
case "--teleport":
teleport = cmd.ParseFloat(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
cmd.Usage(cmd.ErrorCodes["opts"])
}
}
miner := premusk.NewWalker(conf, teleport)
return miner, args
}
示例5: logReporter
func logReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hl:p:",
[]string{
"help",
"level=",
"prefix=",
"show-pr",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
level := "INFO"
prefix := ""
showPr := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-l", "--level":
level = oa.Arg()
case "-p", "--prefix":
prefix = oa.Arg()
case "--show-pr":
showPr = true
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
return reporters.NewLog(fmtr, showPr, level, prefix), args
}
示例6: main
func main() {
short := "hm:"
long := []string{
"help", "mode=",
}
args, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
var mode string
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-m", "--mode":
switch oa.Arg() {
case "create", "read":
mode = oa.Arg()
default:
fmt.Fprintf(os.Stderr, "mode %v not supported\n", oa.Arg())
Usage(ErrorCodes["opts"])
}
}
}
if len(args) != 2 {
fmt.Fprintf(os.Stderr, "Must supply exactly two file paths")
Usage(ErrorCodes["opts"])
}
list_path := args[0]
keys_path := args[1]
f, err := os.Create("stress-" + mode + ".prof")
if err != nil {
panic(err)
}
defer f.Close()
profile_writer = f
switch mode {
case "create":
assert_file_does_not_exist(list_path)
assert_file_does_not_exist(keys_path)
create(list_path, keys_path)
case "read":
assert_file_exist(list_path)
assert_file_exist(keys_path)
read(list_path, keys_path)
}
}
示例7: fileReporter
func fileReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hp:e:n:",
[]string{
"help",
"patterns=",
"embeddings=",
"names=",
"matrices=",
"probabilities=",
"show-pr",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
patterns := "patterns"
embeddings := "embeddings"
names := "names.txt"
matrices := "matrices.json"
probabilities := "probabilities.prs"
showPr := false
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--patterns":
patterns = oa.Arg()
case "-e", "--embeddings":
embeddings = oa.Arg()
case "-n", "--names":
names = oa.Arg()
case "--matrices":
matrices = oa.Arg()
case "--probabilites":
probabilities = oa.Arg()
case "--show-pr":
showPr = true
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
fr, err := reporters.NewFile(conf, fmtr, showPr, patterns, embeddings, names, matrices, probabilities)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v\n", err)
os.Exit(1)
}
return fr, args
}
示例8: main
func main() {
short := "hp:"
long := []string{
"help",
"pattern=",
}
_, optargs, err := getopt.GetOpt(os.Args[1:], short, long)
if err != nil {
log.Print(os.Stderr, err)
Usage(1)
}
patterns := make([]string, 0, 10)
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--pattern":
patterns = append(patterns, oa.Arg())
}
}
if len(patterns) <= 0 {
log.Print("Must supply some regulars expressions!")
Usage(1)
}
asts := make([]frontend.AST, 0, len(patterns))
for _, p := range patterns {
ast, err := frontend.Parse([]byte(p))
if err != nil {
log.Fatal(err)
}
asts = append(asts, ast)
}
lexast := asts[len(asts)-1]
for i := len(asts) - 2; i >= 0; i-- {
lexast = frontend.NewAltMatch(asts[i], lexast)
}
program, err := frontend.Generate(lexast)
if err != nil {
log.Fatal(err)
}
for i, inst := range program {
fmt.Printf("%3d %s\n", i, inst.Serialize())
}
}
示例9: dbscanReporter
func dbscanReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hf:e:g:a:",
[]string{
"help",
"filename=",
"epsilon=",
"gamma=",
"attr=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
clusters := "clusters"
metrics := "metrics"
attr := ""
epsilon := 0.2
gamma := 0.2
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-c", "--clusters-name":
clusters = oa.Arg()
case "-m", "--metrics-name":
metrics = oa.Arg()
case "-a", "--attr":
attr = oa.Arg()
case "-e", "--epsilon":
epsilon = ParseFloat(oa.Arg())
case "-g", "--gamma":
gamma = ParseFloat(oa.Arg())
default:
errors.Logf("ERROR", "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
if attr == "" {
errors.Logf("ERROR", "You must supply --attr=<attr> to dbscan")
Usage(ErrorCodes["opts"])
}
r, err := reporters.NewDbScan(conf, fmtr, clusters, metrics, attr, epsilon, gamma)
if err != nil {
errors.Logf("ERROR", "There was error creating output files\n")
errors.Logf("ERROR", "%v", err)
os.Exit(1)
}
return r, args
}
示例10: uniqueReporter
func uniqueReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
"histogram=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
histogram := ""
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "--histogram":
histogram = oa.Arg()
default:
errors.Logf("ERROR", "Unknown flag '%v'", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
errors.Logf("ERROR", "You must supply an inner reporter to unique")
fmt.Fprintln(os.Stderr, "try: unique file")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
errors.Logf("ERROR", "Unknown reporter '%v'", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
uniq, err := reporters.NewUnique(conf, fmtr, rptr, histogram)
if err != nil {
errors.Logf("ERROR", "Error creating unique reporter '%v'\n", err)
Usage(ErrorCodes["opts"])
}
return uniq, args
}
示例11: chainReporter
func chainReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
default:
errors.Logf("ERROR", "Unknown flag '%v'", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
rptrs := make([]miners.Reporter, 0, 10)
for len(args) >= 1 {
if args[0] == "endchain" {
args = args[1:]
break
}
if _, has := reports[args[0]]; !has {
errors.Logf("ERROR", "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
}
var rptr miners.Reporter
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
rptrs = append(rptrs, rptr)
}
if len(rptrs) == 0 {
errors.Logf("ERROR", "Empty chain")
fmt.Fprintln(os.Stderr, "try: chain log file")
Usage(ErrorCodes["opts"])
}
return &reporters.Chain{rptrs}, args
}
示例12: itemsetType
func itemsetType(argv []string, conf *config.Config) (lattice.Loader, func(lattice.DataType, lattice.PrFormatter) lattice.Formatter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hl:", []string{"help", "loader=", "min-items=", "max-items="},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
loaderType := "int"
min := 0
max := int(math.MaxInt32)
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-l", "--loader":
loaderType = oa.Arg()
case "--min-items":
min = ParseInt(oa.Arg())
case "--max-items":
max = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var loader lattice.Loader
switch loaderType {
case "int":
loader, err = itemset.NewIntLoader(conf, min, max)
default:
fmt.Fprintf(os.Stderr, "Unknown itemset loader '%v'\n", loaderType)
Usage(ErrorCodes["opts"])
}
if err != nil {
log.Panic(err)
}
fmtr := func(_ lattice.DataType, prfmt lattice.PrFormatter) lattice.Formatter {
return &itemset.Formatter{prfmt}
}
return loader, fmtr, args
}
示例13: heapProfileReporter
func heapProfileReporter(rptrs map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hp:a:e:",
[]string{
"help",
"profile=",
"after=",
"every=",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
after := 0
every := 1
profile := ""
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-p", "--patterns":
profile = oa.Arg()
case "-a", "--after":
after = ParseInt(oa.Arg())
case "-e", "--every":
every = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
if profile == "" {
fmt.Fprintf(os.Stderr, "You must supply a location to write the profile (-p) in heap-profile.\n")
os.Exit(1)
}
r, err := reporters.NewHeapProfile(profile, after, every)
if err != nil {
fmt.Fprintf(os.Stderr, "There was error creating output files\n")
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
return r, args
}
示例14: skipReporter
func skipReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"hs:",
[]string{
"help",
"skip=",
},
)
if err != nil {
errors.Logf("ERROR", "%v", err)
Usage(ErrorCodes["opts"])
}
skip := 0
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
case "-s", "--skip":
skip = ParseInt(oa.Arg())
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "You must supply an inner reporter to skip")
fmt.Fprintln(os.Stderr, "try: skip log")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
fmt.Fprintf(os.Stderr, "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
r := reporters.NewSkip(skip, rptr)
return r, args
}
示例15: canonMaxReporter
func canonMaxReporter(reports map[string]Reporter, argv []string, fmtr lattice.Formatter, conf *config.Config) (miners.Reporter, []string) {
args, optargs, err := getopt.GetOpt(
argv,
"h",
[]string{
"help",
},
)
if err != nil {
fmt.Fprintln(os.Stderr, err)
Usage(ErrorCodes["opts"])
}
for _, oa := range optargs {
switch oa.Opt() {
case "-h", "--help":
Usage(0)
default:
fmt.Fprintf(os.Stderr, "Unknown flag '%v'\n", oa.Opt())
Usage(ErrorCodes["opts"])
}
}
var rptr miners.Reporter
if len(args) == 0 {
fmt.Fprintln(os.Stderr, "You must supply an inner reporter to canon-max")
fmt.Fprintln(os.Stderr, "try: unique file")
Usage(ErrorCodes["opts"])
} else if _, has := reports[args[0]]; !has {
fmt.Fprintf(os.Stderr, "Unknown reporter '%v'\n", args[0])
fmt.Fprintln(os.Stderr, "Reporters:")
for k := range reports {
fmt.Fprintln(os.Stderr, " ", k)
}
Usage(ErrorCodes["opts"])
} else {
rptr, args = reports[args[0]](reports, args[1:], fmtr, conf)
}
m, err := reporters.NewCanonMax(rptr)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating canon-max reporter '%v'\n", err)
Usage(ErrorCodes["opts"])
}
return m, args
}