feat: command flags cleanup
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
This commit is contained in:
@ -7,16 +7,9 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
const FlagProxyName = "proxy-name"
|
||||
|
||||
func WithProxyFlags(flags ...cli.Flag) []cli.Flag {
|
||||
baseFlags := clientFlag.ComposeFlags(
|
||||
&cli.StringFlag{
|
||||
Name: FlagProxyName,
|
||||
Usage: "use `PROXY_NAME` as targeted proxy",
|
||||
Value: "",
|
||||
Required: true,
|
||||
},
|
||||
ProxyName(),
|
||||
)
|
||||
|
||||
flags = append(flags, baseFlags...)
|
||||
@ -24,8 +17,58 @@ func WithProxyFlags(flags ...cli.Flag) []cli.Flag {
|
||||
return flags
|
||||
}
|
||||
|
||||
const KeyProxyName = "proxy-name"
|
||||
|
||||
func ProxyName() cli.Flag {
|
||||
return &cli.StringFlag{
|
||||
Name: KeyProxyName,
|
||||
Usage: "use `PROXY_NAME` as targeted proxy",
|
||||
Value: "",
|
||||
Required: true,
|
||||
}
|
||||
}
|
||||
|
||||
const KeyProxyTo = "proxy-to"
|
||||
|
||||
func ProxyTo() cli.Flag {
|
||||
return &cli.StringFlag{
|
||||
Name: KeyProxyTo,
|
||||
Usage: "Set `PROXY_TO` as proxy's destination url",
|
||||
Value: "",
|
||||
Required: true,
|
||||
}
|
||||
}
|
||||
|
||||
const KeyProxyFrom = "proxy-from"
|
||||
|
||||
func ProxyFrom() cli.Flag {
|
||||
return &cli.StringSliceFlag{
|
||||
Name: KeyProxyFrom,
|
||||
Usage: "Set `PROXY_FROM` as proxy's patterns to match incoming requests",
|
||||
Value: cli.NewStringSlice("*"),
|
||||
}
|
||||
}
|
||||
|
||||
const KeyProxyWeight = "proxy-weight"
|
||||
|
||||
func ProxyWeight() cli.Flag {
|
||||
return &cli.IntFlag{
|
||||
Name: KeyProxyWeight,
|
||||
Usage: "Set `PROXY_WEIGHT` as proxy's weight",
|
||||
}
|
||||
}
|
||||
|
||||
const KeyProxyEnabled = "proxy-enabled"
|
||||
|
||||
func ProxyEnabled() cli.Flag {
|
||||
return &cli.BoolFlag{
|
||||
Name: KeyProxyEnabled,
|
||||
Usage: "Enable or disable proxy",
|
||||
}
|
||||
}
|
||||
|
||||
func AssertProxyName(ctx *cli.Context) (store.ProxyName, error) {
|
||||
rawProxyName := ctx.String(FlagProxyName)
|
||||
rawProxyName := ctx.String(KeyProxyName)
|
||||
|
||||
name, err := store.ValidateName(rawProxyName)
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user