Skip to content

Commit

Permalink
Merge pull request #1681 from ripienaar/1665.12
Browse files Browse the repository at this point in the history
(#1665) move filter to a more appropriate place
  • Loading branch information
ripienaar authored May 17, 2022
2 parents 0bca9e6 + 9e909b8 commit dee841b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
8 changes: 4 additions & 4 deletions internal/fs/schemas/builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,13 +427,13 @@
"additionalProperties": {
"type": "string"
}
},
"filter": {
"description": "Optional filters to apply to the request, will be merged with standard options if set",
"$ref": "#/definitions/rpc_filter"
}
}
},
"filter": {
"description": "Optional filters to apply to the request, will be merged with standard options if set",
"$ref": "#/definitions/rpc_filter"
},
"std_filters": {
"type": "boolean",
"description": "Enables standard RPC filters like -C, -I etc",
Expand Down
48 changes: 22 additions & 26 deletions providers/appbuilder/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/choria-io/go-choria/config"
"io"
"os"
"sync"
"time"

"github.com/choria-io/go-choria/config"

"github.com/AlecAivazis/survey/v2"
"github.com/choria-io/go-choria/choria"
"github.com/choria-io/go-choria/client/discovery"
Expand All @@ -29,37 +30,32 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

// TODO: this is essentially a full re-implementation of choria req, not sure it adds value over
// just doing an exec of choria req. However I think in time we might extend this to cover some
// new display options to only show some fields etc, but as it stands I am inclined to remove it
// should we get no additional needs in this one.

type RPCFlag struct {
GenericFlag
ReplyFilter string `json:"reply_filter"`
}

type RPCRequest struct {
Agent string `json:"agent"`
Action string `json:"action"`
Params map[string]string `json:"inputs"`
Agent string `json:"agent"`
Action string `json:"action"`
Params map[string]string `json:"inputs"`
Filter *discovery.StandardOptions `json:"filter"`
}

type RPCCommand struct {
StandardFilter bool `json:"std_filters"`
OutputFormatFlags bool `json:"output_format_flags"`
OutputFormat string `json:"output_format"`
Display string `json:"display"`
DisplayFlag bool `json:"display_flag"`
BatchFlags bool `json:"batch_flags"`
BatchSize int `json:"batch"`
BatchSleep int `json:"batch_sleep"`
NoProgress bool `json:"no_progress"`
AllNodesConfirmPrompt string `json:"all_nodes_confirm_prompt"`
Flags []RPCFlag `json:"flags"`
Request RPCRequest `json:"request"`
Filter *discovery.StandardOptions `json:"filter"`
Transform *GenericTransform `json:"transform"`
StandardFilter bool `json:"std_filters"`
OutputFormatFlags bool `json:"output_format_flags"`
OutputFormat string `json:"output_format"`
Display string `json:"display"`
DisplayFlag bool `json:"display_flag"`
BatchFlags bool `json:"batch_flags"`
BatchSize int `json:"batch"`
BatchSleep int `json:"batch_sleep"`
NoProgress bool `json:"no_progress"`
AllNodesConfirmPrompt string `json:"all_nodes_confirm_prompt"`
Flags []RPCFlag `json:"flags"`
Request RPCRequest `json:"request"`
Transform *GenericTransform `json:"transform"`

StandardCommand
StandardSubCommands
Expand Down Expand Up @@ -219,13 +215,13 @@ func (r *RPC) setupFilter(fw inter.Framework) error {
r.fo = discovery.NewStandardOptions()
}

if r.def.Filter != nil {
err = processStdDiscoveryOptions(r.def.Filter, r.arguments, r.flags, r.cfg)
if r.def.Request.Filter != nil {
err = processStdDiscoveryOptions(r.def.Request.Filter, r.arguments, r.flags, r.cfg)
if err != nil {
return err
}

r.fo.Merge(r.def.Filter)
r.fo.Merge(r.def.Request.Filter)
}

r.fo.SetDefaultsFromChoria(fw)
Expand Down

0 comments on commit dee841b

Please sign in to comment.