Skip to content

Add --json/-j to most get/list commands#1026

Open
alexellis wants to merge 1 commit into
masterfrom
json_flag
Open

Add --json/-j to most get/list commands#1026
alexellis wants to merge 1 commit into
masterfrom
json_flag

Conversation

@alexellis

Copy link
Copy Markdown
Member

Description

Add --json/-j to most get/list commands

Motivation and Context

For the sake of agent-friendliness - adds structured output for consumption from ad-hoc bash/Python scripts, direct parsing etc.

How Has This Been Tested?

Tested by Qwen 3.6 27B against openfaas edge installation to show that the original did not revert, and the new behaviour is in place.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

Remains in Cobra help messages for now - not separately on docs site - but will include in agent-skills when released for the openfaas-function-developer skill.

https://github.com/openfaas/agent-skills

For the sake of agent-friendliness - adds structured output for
consumption from ad-hoc bash/Python scripts, direct parsing etc.

Tested by Qwen 3.6 27B against openfaas edge installation to show
that the original did not revert, and the new behaviour is in place.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
@reviewfn

reviewfn Bot commented Jun 15, 2026

Copy link
Copy Markdown

AI Pull Request Overview

Disclaimer: This review was generated by automated AI and may contain errors. Do not trust its outputs without human verification.

Summary

  • Adds --json/-j output to several get/list-style CLI commands.
  • Most commands switch to json.MarshalIndent over the existing response structs or slices.
  • The main risk is that some --json paths still emit plain text for edge cases, producing output that scripts cannot parse as JSON.
  • No vendor files were included in the scoped diff.

Approval rating (1-10)

6/10. The feature is broadly useful, but structured output needs to be reliable for empty results and warning paths before merge.

Summary per file

Summary per file
File path Summary
commands/describe.go Adds JSON output for function description.
commands/list.go Adds JSON output for function listing.
commands/logs.go Adds --json alias for JSON log formatting.
commands/namespaces_list.go Adds JSON output for namespace listing.
commands/secret_list.go Adds JSON output for secret listing.
commands/secret_unseal.go Adds JSON output for unsealed secrets.
commands/store_describe.go Adds JSON output for store function details.
commands/store_list.go Adds JSON output for store function listing.
commands/template_store_describe.go Adds JSON output for template details.
commands/template_store_list.go Adds JSON output for template listing.
commands/version.go Adds JSON output for CLI, gateway, and provider version info.

Overall Assessment

The implementation is directionally sound and keeps the changes localized, but --json should be treated as a contract that stdout is machine-parseable JSON. A few paths still print human-readable text under valid invocations, which undermines the stated goal of agent/script-friendly output.

Detailed Review

Detailed Review

Findings

Medium: secret list --json prints plain text when no secrets exist

commands/secret_list.go:69

The empty-result branch runs before the new JSON branch, so faas-cli secret list --json emits No secrets found. instead of valid JSON when the gateway returns an empty secret list. That makes the flag unreliable for scripts in a normal cluster state.

A minimal fix is to handle JSON before the human-readable empty message:

if jsonOutput {
	data, err := json.MarshalIndent(secrets, "", "  ")
	if err != nil {
		return fmt.Errorf("failed to marshal JSON: %w", err)
	}
	fmt.Fprintln(cmd.OutOrStdout(), string(data))
	return nil
}

if len(secrets) == 0 {
	fmt.Printf("No secrets found.\n")
	return nil
}

Medium: store list --json prints plain text when filtering returns no functions

commands/store_list.go:57

The no-results branch still prints No functions found in the store... and returns before the JSON branch. For faas-cli store list --json --filter <platform-with-no-results> or any unsupported platform value, stdout is not JSON even though --json was requested.

If the command is intended for structured consumption, the JSON path should return an empty array or a structured error object instead of human text. The least surprising behavior is to marshal filteredFunctions first when jsonOutput is true, then keep the existing hint only for text output.

Medium: TLS warnings corrupt JSON output for log and secret list commands

commands/logs.go:96

commands/secret_list.go:50

Both commands support --json in this PR and still print the insecure TLS warning to stdout when --tls-no-verify is used with an HTTP gateway. That prepends a non-JSON line before the JSON payload, so common invocations such as faas-cli logs FN --json --tls-no-verify or faas-cli secret list --json --tls-no-verify cannot be piped into jq or parsed by automation.

Move these warnings to stderr, or suppress them for --json, so stdout remains a single JSON stream.

AI agent details.

Agent processing time: 2m21.91s
Environment preparation time: 10.896s
Total time from webhook: 2m46.24s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant