flags pkg : but im not convinced this is right
This commit is contained in:
parent
8bd0da003e
commit
f483e08105
4 changed files with 57 additions and 48 deletions
24
flags/flags.go
Normal file
24
flags/flags.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package flags
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Flag string
|
||||
|
||||
func (f Flag) Dash() string {
|
||||
return fmt.Sprintf("--%s", f)
|
||||
}
|
||||
|
||||
// prepend --flag to args if a flag isn't there:
|
||||
// allows trailing flags:
|
||||
// um tag foo --invert
|
||||
// becomes:
|
||||
// um tag --query foo --invert
|
||||
func PrependFlagToArgs(args []string, flag Flag) []string {
|
||||
if len(args) >= 1 && !strings.HasPrefix(args[0], "-") {
|
||||
args = append([]string{flag.Dash()}, args...)
|
||||
}
|
||||
return args
|
||||
}
|
||||
Loading…
Reference in a new issue