| 1 |
|
| 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 |
|
| 20 |
|
| 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 |
|
| 32 |
|
| 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 |
|
| 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 |
} |