本文整理匯總了Golang中github.com/droundy/goopt.Parse函數的典型用法代碼示例。如果您正苦於以下問題:Golang Parse函數的具體用法?Golang Parse怎麽用?Golang Parse使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Parse函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: main
func main() {
goopt.Suite = "XQZ coreutils"
goopt.Author = "Aaron Muir Hamilton"
goopt.Version = "Sleep v0.1"
goopt.Summary = "Waits for a duration before continuing."
goopt.Usage = func() string {
return fmt.Sprintf("Usage of %s:\n\t %s STRING\n\tor %s OPTION\n", os.Args[0], os.Args[0], os.Args[0]) +
goopt.Summary + "\n\n" + goopt.Help()
}
goopt.Description = func() string {
return goopt.Summary + "\n\nUnless an option is passed to it."
}
goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
goopt.Parse(nil)
duration, err := time.ParseDuration(os.Args[1])
if err != nil {
number, interr := strconv.ParseFloat(os.Args[1], 64)
if interr != nil {
fmt.Println(err)
os.Exit(0)
}
duration := time.Duration(number) * time.Second
time.Sleep(duration)
os.Exit(0)
}
time.Sleep(duration)
}
示例2: cliSetup
func cliSetup() *cliOptions {
options := newCliOptions()
var httpVerb = goopt.StringWithLabel([]string{"-X", "--command"}, options.httpVerb,
"COMMAND", fmt.Sprintf("HTTP verb for request: %s", HttpVerbs))
var httpHeaders = goopt.Strings([]string{"-H", "--header"},
"KEY:VALUE", "Custom HTTP Headers to be sent with request (can pass multiple times)")
var postData = goopt.StringWithLabel([]string{"-d", "--data"}, options.postData,
"DATA", "HTTP Data for POST")
var timeOut = goopt.IntWithLabel([]string{"-t", "--timeout"}, options.timeout,
"TIMEOUT", "Timeout in seconds for request")
var shouldRedirect = goopt.Flag([]string{"-r", "--redirect"}, []string{}, "Follow redirects", "")
var isVerbose = goopt.Flag([]string{"-v", "--verbose"}, []string{}, "Verbose output", "")
var hasColor = goopt.Flag([]string{"-c", "--color"}, []string{}, "Colored output", "")
var isInsecureSSL = goopt.Flag([]string{"-k", "--insecure"}, []string{}, "Allow insecure https connections", "")
goopt.Summary = "Golang based http client program"
goopt.Parse(nil)
options.httpVerb = *httpVerb
options.httpHeaders = *httpHeaders
options.postData = *postData
options.timeout = *timeOut
options.verbose = *isVerbose
options.redirect = *shouldRedirect
options.color = *hasColor
options.sslInsecure = *isInsecureSSL
options.arguments = goopt.Args
exitWithMessageIfNonZero(validateOptions(options))
exitWithMessageIfNonZero(validateArguments(options))
return options
}
示例3: main
func main() {
goopt.Suite = "XQZ coreutils"
goopt.Author = "William Pearson"
goopt.Version = "Unlink v0.1"
goopt.Summary = "Uses unlink to remove FILE"
goopt.Usage = func() string {
return fmt.Sprintf("Usage:\t%s FILE\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
}
goopt.Description = func() string {
return goopt.Summary + "\n\nUnless an option is passed to it."
}
goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
goopt.Parse(nil)
switch {
case len(os.Args) == 1:
fmt.Println("Missing filenames")
case len(os.Args) > 2:
fmt.Println("Too many filenames")
}
if len(os.Args) != 2 {
os.Exit(1)
}
file := os.Args[1]
if err := syscall.Unlink(file); err != nil {
fmt.Println("Encountered an error during unlinking: %v", err)
os.Exit(1)
}
return
}
示例4: main
func main() {
goopt.Description = func() string {
return "Example program for using the goopt flag library."
}
goopt.Version = "1.0"
goopt.Summary = "goopt demonstration program"
goopt.Parse(nil)
defer fmt.Print("\033[0m") // defer resetting the terminal to default colors
switch *color {
case "default":
case "red":
fmt.Print("\033[31m")
case "green":
fmt.Print("\033[32m")
case "blue":
fmt.Print("\033[34m")
default:
panic("Unrecognized color!") // this should never happen!
}
log("I have now set the color to", *color, ".")
for i := 0; i < *repetitions; i++ {
fmt.Println("Greetings,", *username)
log("You have", *repetitions, "children.")
for _, child := range *children {
fmt.Println("I also greet your child, whose name is", child)
}
}
}
示例5: main
func main() {
goopt.Summary = "silly test program"
goopt.Parse(nil)
if *amVerbose {
fmt.Println("I am verbose.")
}
if *amHappy {
fmt.Println("I am happy")
} else {
fmt.Println("I am unhappy")
}
fmt.Println("Your name is", *foo)
fmt.Println(*bar, "... Did I scare you?")
fmt.Println("I am going so very", *speed, "!!!")
fmt.Print("Here is the saying:")
for _, w := range *words {
fmt.Print(" ", w)
}
fmt.Println()
fmt.Println(*baz)
fmt.Print("Back in my day,")
for _, w := range goopt.Args {
fmt.Print(" ", w)
}
fmt.Println()
fmt.Printf("What's up, man%s\n", strings.Repeat("?", *width))
}
示例6: main
func main() {
goopt.Author = Author
goopt.Version = Version
goopt.Summary = Summary
goopt.Parse(nil)
if len(goopt.Args) == 0 {
println(goopt.Usage())
return
}
if *concurrency > *reqs {
fmt.Printf("You can't have concurrency higher than number of requests\n")
return
}
url, ip, err := getURL(goopt.Args[0])
if err != nil {
fmt.Printf("url is invalid: %s\n", err)
return
}
runtime.GOMAXPROCS(*cpus)
fmt.Printf("Statistics for requests to %s\n", goopt.Args[0])
results, total := start(url, ip, *reqs, *concurrency)
printStats(results, total)
}
示例7: main
func main() {
if len(os.Args) < 2 {
fmt.Fprintf(os.Stderr, "Usage: %s -h for help\n", os.Args[0])
os.Exit(1)
}
config_file := goopt.String([]string{"-c", "--config"}, "nrpe.cfg",
"config file to use")
//the first option, will be the default, if the -m isnt given
run_mode := goopt.Alternatives([]string{"-m", "--mode"},
[]string{"foreground", "daemon", "systemd"}, "operating mode")
goopt.Parse(nil)
//implement different run modes..
fmt.Println(*run_mode)
config_obj := new(read_config.ReadConfig)
config_obj.Init(*config_file)
err := config_obj.ReadConfigFile()
common.CheckError(err)
//extract the commands command[cmd_name] = "/bin/foobar"
config_obj.ReadCommands()
config_obj.ReadPrivileges()
//TODO check for errors
//what we gonna do with the group?
pwd := drop_privilege.Getpwnam(config_obj.Nrpe_user)
drop_privilege.DropPrivileges(int(pwd.Uid), int(pwd.Gid))
//we have to read it from config
service := ":5666"
err = setupSocket(4, service, config_obj)
common.CheckError(err)
}
示例8: main
func main() {
goopt.Parse(func() []string { return []string{} })
syscall.Umask(0077) // Turn off read/write/execute priviledges for others
if len(goopt.Args) < 1 {
fmt.Println("You need to provide a go file argument.")
os.Exit(1)
}
execname := goopt.Args[0] + ".secret"
e := compile.Compile(execname, goopt.Args)
if e != nil {
fmt.Fprintln(os.Stderr, e)
os.Exit(1)
}
if *outname == "FILENAME.go" {
fmt.Fprintln(os.Stderr, "secretrun requires a -o argument!")
os.Exit(1)
}
e = deps.Exec("./"+execname, *outname)
os.Remove(execname)
if e != nil {
fmt.Fprintln(os.Stderr, e)
os.Exit(1)
}
}
示例9: main
func main() {
goopt.Suite = "XQZ coreutils"
goopt.Author = "William Pearson"
goopt.Version = "Link v0.1"
goopt.Summary = "Creates a link to FILE1 called FILE2"
goopt.Usage = func() string {
return fmt.Sprintf("Usage:\t%s FILE1 FILE2\n or:\t%s OPTION\n", os.Args[0], os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
}
goopt.Description = func() string {
return goopt.Summary + "\n\nUnless an option is passed to it."
}
goopt.NoArg([]string{"-v", "--version"}, "outputs version information and exits", version)
goopt.Parse(nil)
switch {
case len(os.Args) == 1:
fmt.Println("Missing filenames")
case len(os.Args) == 2:
fmt.Println("Missing filename after '%s'", os.Args[1])
case len(os.Args) > 3:
fmt.Println("Too many filenames")
}
if len(os.Args) != 3 {
os.Exit(1)
}
file1 := os.Args[1]
file2 := os.Args[2]
if err := os.Link(file1, file2); err != nil {
fmt.Println("Encountered an error during linking: %v", err)
os.Exit(1)
}
return
}
示例10: main
func main() {
goopt.Parse(func() []string { return nil })
if len(goopt.Args) > 0 {
x, err := parser.ParseFiles(myfiles, goopt.Args, 0)
die(err)
fmt.Fprintln(os.Stderr, "Parsed: ", *x["main"])
die(typechecker.CheckPackage(myfiles, x["main"], nil))
fmt.Fprintln(os.Stderr, "Checked: ", *x["main"])
//for _,a := range x["main"].Files {
// die(printer.Fprint(os.Stdout, a))
//}
aaa := x86.StartData
var bbb *Stack
var cv = CompileVisitor{&aaa, make(map[string]string), bbb.New("global")}
ast.Walk(StringVisitor(cv), x["main"])
cv.Append(x86.StartText...)
ast.Walk(&cv, x["main"])
// Here we just add a crude debug library
cv.Append(x86.Debugging...)
ass := x86.Assembly(*cv.assembly)
//fmt.Println(ass)
die(elf.AssembleAndLink(goopt.Args[0][:len(goopt.Args[0])-3], []byte(ass)))
}
}
示例11: Init
func Init(summary string, description func() string, getopts func() []string ) {
goopt.Author = "David Roundy"
goopt.Description = description
goopt.Summary = summary
goopt.Version = "0.0"
goopt.Suite = "Iolaus"
goopt.Parse(getopts)
}
示例12: setup
// Setup some flag-related options and parse said flags.
func setup() {
goopt.Description = func() string {
return "A dead-simple markdown conversion program."
}
goopt.Version = "1.0"
goopt.Summary = "Markdown converter"
goopt.Parse(nil)
}
示例13: main
func main() {
opt.Parse(nil)
if *showVersion {
fmt.Printf("Gob v%s\n", GOB_VERSION)
return
}
if len(opt.Args) < 1 {
fmt.Println("Need to specify an input file")
return
}
for _, name := range opt.Args {
if len(opt.Args) > 1 {
fmt.Printf("==== %s ====\n", name)
}
file, err := os.Open(name)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
parser := parse.NewParser(name, file)
unit, err := parser.Parse()
if err != nil {
fmt.Println(err)
}
if err = unit.Verify(); err != nil {
fmt.Println(err)
}
if *parseOnly {
continue
}
var outName string = *outFile
if outName == "" {
outName = path.Base(name) + ".c"
}
if file, err = os.Create(outName); err != nil {
fmt.Println(err)
os.Exit(1)
}
var emit emit.CEmitter
emit.Emit(file, unit)
file.Close()
}
}
示例14: main
func main() {
goopt.Version = Version
goopt.Summary = Summary
goopt.Parse(nil)
if *showSummary && *doWatch {
errhandle(fmt.Errorf("--summary and --watch do not mix together well"))
}
if *showVersion {
out("gostatic %s\n", goopt.Version)
return
}
if *showProcessors {
ProcessorSummary()
return
}
if len(goopt.Args) == 0 {
println(goopt.Usage())
return
}
config, err := NewSiteConfig(goopt.Args[0])
errhandle(err)
if *showConfig {
x, err := json.MarshalIndent(config, "", " ")
errhandle(err)
println(string(x))
return
}
site := NewSite(config)
if *showSummary {
site.Summary()
} else {
site.Render()
}
if *doWatch {
StartWatcher(config)
out("Starting server at *:%s...\n", *port)
fs := http.FileServer(http.Dir(config.Output))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
fs.ServeHTTP(w, r)
})
err := http.ListenAndServe(":"+*port, nil)
errhandle(err)
}
}
示例15: main
func main() {
var no_cog = goopt.Flag([]string{"-C", "--no-cog"}, []string{"-c", "--cog"},
"skip opening in cog", "open in cog")
var no_delete = goopt.Flag([]string{"-D", "--no-delete"}, []string{"-d", "--delete"},
"skip deleting original zip", "delete original zip")
goopt.Parse(nil)
boomkat(goopt.Args[0], *no_cog, *no_delete)
}