Skip to content

Commit

Permalink
feat(tarianctl): update remove constraints to accept multiple names
Browse files Browse the repository at this point in the history
  • Loading branch information
andylibrian committed Nov 21, 2021
1 parent 6e0aa82 commit 8008c56
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions pkg/tarianctl/cmd/remove/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,41 @@ import (

func NewRemoveConstraintsCommand() *cli.Command {
return &cli.Command{
Name: "constraints",
Usage: "Remove constraints from the Tarian Server.",
Name: "constraints",
Aliases: []string{"constraint"},
Usage: "Remove constraints from the Tarian Server.",
UsageText: "Tarianctl remove constraints [command options] names...",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "namespace",
Aliases: []string{"n"},
Usage: "The namespace scope for the constraint to be removed",
Value: "default",
},
&cli.StringFlag{
Name: "name",
Usage: "The name scope for the constraint to be removed",
Value: "",
Required: true,
},
},
Action: func(c *cli.Context) error {
if c.Args().Len() == 0 {
cli.ShowSubcommandHelpAndExit(c, 1)
}

logger := logger.GetLogger(c.String("log-level"), c.String("log-encoding"))
util.SetLogger(logger)

opts := util.ClientOptionsFromCliContext(c)
client, _ := client.NewConfigClient(c.String("server-address"), opts...)

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
response, err := client.RemoveConstraint(ctx, &tarianpb.RemoveConstraintRequest{Namespace: c.String("namespace"), Name: c.String("name")})
cancel()
for _, name := range c.Args().Slice() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
response, err := client.RemoveConstraint(ctx, &tarianpb.RemoveConstraintRequest{Namespace: c.String("namespace"), Name: name})
cancel()

if err != nil {
logger.Fatal(err)
}
if err != nil {
logger.Fatal(err)
}

if response.GetSuccess() {
fmt.Println("Constraint is deleted succesfully")
if response.GetSuccess() {
fmt.Printf("Constraint %s is deleted succesfully\n", name)
}
}

return nil
Expand Down

0 comments on commit 8008c56

Please sign in to comment.