Implement boolOption in galenectl.
This commit is contained in:
1 parent
135630ba5c
commit
bde8f01b52
1 file changed
+34
-5
+34
-5
@@ -18,6 +18,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -989,6 +990,35 @@ func userURL(wildcard bool, groupname, username string) (string, error) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type boolOption struct {
|
||||||
|
set bool
|
||||||
|
value bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *boolOption) Set(value string) error {
|
||||||
|
v, err := strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
o.value = v
|
||||||
|
o.set = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *boolOption) String() string {
|
||||||
|
if o == nil {
|
||||||
|
return "(nil)"
|
||||||
|
}
|
||||||
|
if !o.set {
|
||||||
|
return "(unset)"
|
||||||
|
}
|
||||||
|
return strconv.FormatBool(o.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *boolOption) IsBoolFlag() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
type stringOption struct {
|
type stringOption struct {
|
||||||
set bool
|
set bool
|
||||||
value string
|
value string
|
||||||
@@ -1323,14 +1353,13 @@ func listTokensCmd(cmdname string, args []string) {
|
|||||||
func createTokenCmd(cmdname string, args []string) {
|
func createTokenCmd(cmdname string, args []string) {
|
||||||
var groupname stringOption
|
var groupname stringOption
|
||||||
var username, permissions string
|
var username, permissions string
|
||||||
var includeSubgroups bool
|
var includeSubgroups boolOption
|
||||||
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
|
||||||
setUsage(cmd, cmdname, "%v [option...] %v [option...]\n",
|
setUsage(cmd, cmdname, "%v [option...] %v [option...]\n",
|
||||||
os.Args[0], cmdname,
|
os.Args[0], cmdname,
|
||||||
)
|
)
|
||||||
cmd.Var(&groupname, "group", "group `name`")
|
cmd.Var(&groupname, "group", "group `name`")
|
||||||
cmd.BoolVar(&includeSubgroups, "include-subgroups", false,
|
cmd.Var(&includeSubgroups, "include-subgroups", "include subgroups")
|
||||||
"include subgroups")
|
|
||||||
cmd.StringVar(&username, "user", "", "encode user `name` in token")
|
cmd.StringVar(&username, "user", "", "encode user `name` in token")
|
||||||
cmd.StringVar(&permissions, "permissions", "present", "permissions")
|
cmd.StringVar(&permissions, "permissions", "present", "permissions")
|
||||||
cmd.Parse(args)
|
cmd.Parse(args)
|
||||||
@@ -1356,8 +1385,8 @@ func createTokenCmd(cmdname string, args []string) {
|
|||||||
if username != "" {
|
if username != "" {
|
||||||
t["username"] = username
|
t["username"] = username
|
||||||
}
|
}
|
||||||
if includeSubgroups {
|
if includeSubgroups.set {
|
||||||
t["includeSubgroups"] = true
|
t["includeSubgroups"] = includeSubgroups.value
|
||||||
}
|
}
|
||||||
|
|
||||||
u, err := url.JoinPath(
|
u, err := url.JoinPath(
|
||||||
|
|||||||
Reference in new issue
Block a user