From 9e909b8bc9c0526eb8d47437b362fbcf82fbad02 Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Tue, 17 May 2022 17:40:42 +0200 Subject: [PATCH] (#1665) move filter to a more appropriate place Signed-off-by: R.I.Pienaar --- internal/fs/schemas/builder.json | 8 +++--- providers/appbuilder/rpc.go | 48 +++++++++++++++----------------- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/internal/fs/schemas/builder.json b/internal/fs/schemas/builder.json index 01cad4053..5f0839aaf 100644 --- a/internal/fs/schemas/builder.json +++ b/internal/fs/schemas/builder.json @@ -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", diff --git a/providers/appbuilder/rpc.go b/providers/appbuilder/rpc.go index 622e6d056..fd39d730d 100644 --- a/providers/appbuilder/rpc.go +++ b/providers/appbuilder/rpc.go @@ -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" @@ -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 @@ -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)