feat(client): tenant management commands
This commit is contained in:
37
internal/command/client/tenant/flag/flag.go
Normal file
37
internal/command/client/tenant/flag/flag.go
Normal file
@ -0,0 +1,37 @@
|
||||
package flag
|
||||
|
||||
import (
|
||||
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
|
||||
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func WithTenantFlags(flags ...cli.Flag) []cli.Flag {
|
||||
baseFlags := clientFlag.ComposeFlags(
|
||||
&cli.StringFlag{
|
||||
Name: "tenant-id",
|
||||
Usage: "use `TENANT_ID` as targeted tenant",
|
||||
Value: "",
|
||||
},
|
||||
)
|
||||
|
||||
flags = append(flags, baseFlags...)
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
func AssertTenantID(ctx *cli.Context) (datastore.TenantID, error) {
|
||||
rawTenantID := ctx.String("tenant-id")
|
||||
|
||||
if rawTenantID == "" {
|
||||
return "", errors.New("flag 'tenant-id' is required")
|
||||
}
|
||||
|
||||
tenantID, err := datastore.ParseTenantID(rawTenantID)
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
}
|
||||
|
||||
return tenantID, nil
|
||||
}
|
Reference in New Issue
Block a user