Skip to content

Commit

Permalink
cli: add filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
schmichael committed Feb 24, 2022
1 parent 3351579 commit 79f4315
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions command/operator_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ Operator API Specific Options:
if the -token flag is explicitly used, the token will also be included in
the output.
-filter <query>
Specifies an expression used to filter query results.
-H <Header>
Adds an additional HTTP header to the request. May be specified more than
once. These headers take precedent over automatically ones such as
Expand Down Expand Up @@ -95,11 +98,13 @@ func (*OperatorAPICommand) Name() string { return "operator api" }

func (c *OperatorAPICommand) Run(args []string) int {
var dryrun bool
var filter string
headerFlags := newHeaderFlags()

flags := c.Meta.FlagSet(c.Name(), FlagSetClient)
flags.Usage = func() { c.Ui.Output(c.Help()) }
flags.BoolVar(&dryrun, "dryrun", false, "")
flags.StringVar(&filter, "filter", "", "")
flags.BoolVar(&c.verboseFlag, "verbose", false, "")
flags.StringVar(&c.method, "X", "", "")
flags.Var(headerFlags, "H", "")
Expand Down Expand Up @@ -160,6 +165,13 @@ func (c *OperatorAPICommand) Run(args []string) int {
return 2
}

// Set Filter query param
if filter != "" {
q := path.Query()
q.Set("filter", filter)
path.RawQuery = q.Encode()
}

if dryrun {
out, err := c.apiToCurl(config, headerFlags.headers, path)
if err != nil {
Expand Down

0 comments on commit 79f4315

Please sign in to comment.