Skip to content

Commit

Permalink
Merge pull request #1671 from ripienaar/1665.3
Browse files Browse the repository at this point in the history
(#1665) allow output format to be forced
  • Loading branch information
ripienaar authored May 12, 2022
2 parents e7e3743 + 659b251 commit 6baa548
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
7 changes: 6 additions & 1 deletion internal/fs/schemas/builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,16 @@
"description": "Enables standard RPC filters like -C, -I etc, can not be combined with filters",
"default": false
},
"output_formats_flags": {
"output_format_flags": {
"type": "boolean",
"description": "Enable flags to adjust the output format like --json, --table etc",
"default": false
},
"output_format": {
"type": "string",
"description": "Sets a specific output format, not compatible with output_format_flags",
"enum": ["senders", "json", "table"]
},
"display_flag": {
"type": "boolean",
"description": "Enables the --display flag, not compatible with display",
Expand Down
43 changes: 30 additions & 13 deletions providers/appbuilder/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ type RPCRequest struct {
}

type RPCCommand struct {
StandardFilter bool `json:"std_filters"`
OutputFormatsFlags bool `json:"output_formats_flags"`
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"`
Arguments []GenericArgument `json:"arguments"`
Flags []RPCFlag `json:"flags"`
Request RPCRequest `json:"request"`
Filter *discovery.StandardOptions `json:"filter"`
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"`
Arguments []GenericArgument `json:"arguments"`
Flags []RPCFlag `json:"flags"`
Request RPCRequest `json:"request"`
Filter *discovery.StandardOptions `json:"filter"`

StandardCommand
StandardSubCommands
Expand Down Expand Up @@ -109,10 +110,26 @@ func (r *RPC) CreateCommand(app inter.FlagApp) (*kingpin.CmdClause, error) {
r.Arguments[a.Name] = arg.String()
}

if r.def.OutputFormatsFlags {
switch {
case r.def.OutputFormatFlags && r.def.OutputFormat != "":
return nil, fmt.Errorf("only one of output_format_flags and output_format may be supplied to command %s", r.def.Name)

case r.def.OutputFormatFlags:
r.cmd.Flag("senders", "List only the names of matching nodes").BoolVar(&r.senders)
r.cmd.Flag("json", "Render results as JSON").BoolVar(&r.json)
r.cmd.Flag("table", "Render results as a table").BoolVar(&r.table)

case r.def.OutputFormat == "senders":
r.senders = true

case r.def.OutputFormat == "json":
r.json = true

case r.def.OutputFormat == "table":
r.table = true

case r.def.OutputFormat != "":
return nil, fmt.Errorf("invalid output format %q, valid formats are senders, json and table", r.def.OutputFormat)
}

switch {
Expand Down

0 comments on commit 6baa548

Please sign in to comment.