本文整理匯總了Golang中github.com/droundy/goopt.NoArg函數的典型用法代碼示例。如果您正苦於以下問題:Golang NoArg函數的具體用法?Golang NoArg怎麽用?Golang NoArg使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NoArg函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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
}
示例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.Author = "William Pearson"
goopt.Version = "Rmdir"
goopt.Summary = "Remove each DIRECTORY if it is empty"
goopt.Usage = func() string {
return fmt.Sprintf("Usage:\t%s [OPTION]... DIRECTORY...\n", os.Args[0]) + goopt.Summary + "\n\n" + goopt.Help()
}
goopt.Description = func() string {
return goopt.Summary + "\n\nUnless --help or --version is passed."
}
ignorefail := goopt.Flag([]string{"--ignore-fail-on-non-empty"}, nil,
"Ignore each failure that is from a directory not being empty", "")
parents := goopt.Flag([]string{"-p", "--parents"}, nil, "Remove DIRECTORY and ancestors if ancestors become empty", "")
verbose := goopt.Flag([]string{"-v", "--verbose"}, nil, "Output each directory as it is processed", "")
goopt.NoArg([]string{"--version"}, "outputs version information and exits", coreutils.Version)
goopt.Parse(nil)
if len(goopt.Args) == 0 {
coreutils.PrintUsage()
}
for i := range goopt.Args {
filelisting, err := ioutil.ReadDir(goopt.Args[i])
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", os.Args[i+1], err)
defer os.Exit(1)
continue
}
if !*ignorefail && len(filelisting) > 0 {
fmt.Fprintf(os.Stderr, "Failed to remove '%s' directory is non-empty\n", goopt.Args[i])
defer os.Exit(1)
continue
}
if *verbose {
fmt.Printf("Removing directory %s\n", goopt.Args[i])
}
err = os.Remove(goopt.Args[i])
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to remove %s: %v\n", goopt.Args[i], err)
defer os.Exit(1)
continue
}
if !*parents {
continue
}
dir := goopt.Args[i]
if dir[len(dir)-1] == '/' {
dir = filepath.Dir(dir)
}
if removeEmptyParents(dir, *verbose, *ignorefail) {
defer os.Exit(1)
}
}
return
}
示例5: init
func init() {
goopt.NoArg([]string{"--verbose", "-v"}, "Increase verbosity",
func() error {
verbose++
return nil
})
goopt.NoArg([]string{"--silent", "-q"}, "Decrease verbosity",
func() error {
verbose--
return nil
})
goopt.NoArg([]string{"--push"}, "Use PUSH socket type", func() error {
return setSocket(push.NewSocket)
})
goopt.NoArg([]string{"--pull"}, "Use PULL socket type", func() error {
return setSocket(pull.NewSocket)
})
goopt.NoArg([]string{"--pub"}, "Use PUB socket type", func() error {
return setSocket(pub.NewSocket)
})
goopt.NoArg([]string{"--sub"}, "Use SUB socket type", func() error {
return setSocket(sub.NewSocket)
})
goopt.NoArg([]string{"--req"}, "Use REQ socket type", func() error {
return setSocket(req.NewSocket)
})
goopt.NoArg([]string{"--rep"}, "Use REP socket type", func() error {
return setSocket(rep.NewSocket)
})
goopt.NoArg([]string{"--surveyor"}, "Use SURVEYOR socket type",
func() error {
return setSocket(surveyor.NewSocket)
})
goopt.NoArg([]string{"--respondent"}, "Use RESPONDENT socket type",
func() error {
return setSocket(respondent.NewSocket)
})
goopt.NoArg([]string{"--bus"}, "Use BUS socket type", func() error {
return setSocket(bus.NewSocket)
})
goopt.NoArg([]string{"--pair"}, "Use PAIR socket type", func() error {
return setSocket(pair.NewSocket)
})
goopt.NoArg([]string{"--star"}, "Use STAR socket type", func() error {
return setSocket(star.NewSocket)
})
goopt.ReqArg([]string{"--bind"}, "ADDR", "Bind socket to ADDR",
addListen)
goopt.ReqArg([]string{"--connect"}, "ADDR", "Connect socket to ADDR",
addDial)
goopt.ReqArg([]string{"--bind-ipc", "-X"}, "PATH",
"Bind socket to IPC PATH", addListenIPC)
goopt.ReqArg([]string{"--connect-ipc", "-x"}, "PATH",
"Connect socket to IPC PATH", addDialIPC)
goopt.ReqArg([]string{"--bind-local", "-L"}, "PORT",
"Bind socket to TCP localhost PORT", addListenLocal)
goopt.ReqArg([]string{"--connect-local", "-l"}, "PORT",
"Connect socket to TCP localhost PORT", addDialLocal)
goopt.ReqArg([]string{"--subscribe"}, "PREFIX",
"Subcribe to PREFIX (default is wildcard)", addSub)
goopt.ReqArg([]string{"--recv-timeout"}, "SEC", "Set receive timeout",
func(to string) error {
var err error
recvTimeout, err = strconv.Atoi(to)
if err != nil {
return errors.New("value not an integer")
}
return nil
})
goopt.ReqArg([]string{"--send-timeout"}, "SEC", "Set send timeout",
func(to string) error {
var err error
if sendTimeout, err = strconv.Atoi(to); err != nil {
return errors.New("value not an integer")
}
return nil
})
goopt.ReqArg([]string{"--send-delay", "-d"}, "SEC",
"Set initial send delay",
func(to string) error {
var err error
if sendDelay, err = strconv.Atoi(to); err != nil {
return errors.New("value not an integer")
}
return nil
})
goopt.NoArg([]string{"--raw"}, "Raw output, no delimiters",
func() error {
return setFormat("raw")
})
goopt.NoArg([]string{"--ascii", "-A"}, "ASCII output, one per line",
func() error {
return setFormat("ascii")
})
goopt.NoArg([]string{"--quoted", "-Q"}, "Quoted output, one per line",
func() error {
return setFormat("quoted")
})
goopt.NoArg([]string{"--msgpack"},
//.........這裏部分代碼省略.........