Debian Codegraph @

optstyle_other.go

raw symbols SCIP
1 // +build !windows
2
3 package flags
4
5 import (
6 "strings"
7 )
8
9 const (
10 defaultShortOptDelimiter = '-'
11 defaultLongOptDelimiter = "--"
12 defaultNameArgDelimiter = '='
13 )
14
15 func argumentIsOption(arg string) bool {
16 return len(arg) > 0 && arg[0] == '-'
17 }
18
19 // stripOptionPrefix returns the option without the prefix and whether or
20 // not the option is a long option or not.
21 func stripOptionPrefix(optname string) (string, bool) {
22 if strings.HasPrefix(optname, "--") {
23 return optname[2:], true
24 } else if strings.HasPrefix(optname, "-") {
25 return optname[1:], false
26 }
27
28 return optname, false
29 }
30
31 // splitOption attempts to split the passed option into a name and an argument.
32 // When there is no argument specified, nil will be returned for it.
33 func splitOption(option string) (string, *string) {
34 pos := strings.Index(option, "=")
35 if pos >= 0 {
36 rest := option[pos+1:]
37 return option[:pos], &rest
38 }
39
40 return option, nil
41 }
42
43 // newHelpGroup returns a new group that contains default help parameters.
44 func newHelpGroup(showHelp func() error) *Group {
45 var help struct {
46 ShowHelp func() error `short:"h" long:"help" description:"Show this help message"`
47 }
48 help.ShowHelp = showHelp
49 return NewGroup("Help Options", &help)
50 }