35 lines
727 B
Go
35 lines
727 B
Go
|
package flag
|
||
|
|
||
|
import (
|
||
|
clientFlag "forge.cadoles.com/cadoles/bouncer/internal/command/client/flag"
|
||
|
"forge.cadoles.com/cadoles/bouncer/internal/store"
|
||
|
"github.com/pkg/errors"
|
||
|
"github.com/urfave/cli/v2"
|
||
|
)
|
||
|
|
||
|
func WithProxyFlags(flags ...cli.Flag) []cli.Flag {
|
||
|
baseFlags := clientFlag.ComposeFlags(
|
||
|
&cli.StringFlag{
|
||
|
Name: "name",
|
||
|
Usage: "use `NAME` as targeted proxy",
|
||
|
Value: "",
|
||
|
Required: true,
|
||
|
},
|
||
|
)
|
||
|
|
||
|
flags = append(flags, baseFlags...)
|
||
|
|
||
|
return flags
|
||
|
}
|
||
|
|
||
|
func AssertProxyName(ctx *cli.Context) (store.ProxyName, error) {
|
||
|
rawProxyName := ctx.String("name")
|
||
|
|
||
|
name, err := store.ValidateName(rawProxyName)
|
||
|
if err != nil {
|
||
|
return "", errors.WithStack(err)
|
||
|
}
|
||
|
|
||
|
return store.ProxyName(name), nil
|
||
|
}
|