Skip to content

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

Merged
alexellis merged 5 commits into
masterfrom
json_flag
Jun 16, 2026
Merged

Add --json/-j to most get/list commands#1026
alexellis merged 5 commits 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

@reviewfn

This comment has been minimized.

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

This comment has been minimized.

When secret gen goes into a file, we don't want a newline trailing
as many programs will pipe this file into i.e. a curl header.

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

This comment has been minimized.

@derek derek Bot added the no-dco label Jun 16, 2026
@reviewfn

This comment has been minimized.

@derek

derek Bot commented Jun 16, 2026

Copy link
Copy Markdown

Thank you for your contribution. unfortunately, one or more of your commits are missing the required "Signed-off-by:" statement. Signing off is part of the Developer Certificate of Origin (DCO) which is used by this project.

Read the DCO and project contributing guide carefully, and amend your commits using the git CLI. Note that this does not require any cryptography, keys or special steps to be taken.

💡 Shall we fix this?

This will only take a few moments.

First, clone your fork and checkout this branch using the git CLI.

Next, set up your real name and email address:

git config --global user.name "Your Full Name"
git config --global user.email "you@domain.com"

Finally, run one of these commands to add the "Signed-off-by" line to your commits.

If you only have one commit so far then run: git commit --amend --signoff and then git push --force.
If you have multiple commits, watch this video.

Check that the message has been added properly by running "git log".

@reviewfn

This comment has been minimized.

* Uses Go 1.26 to build Go code
* Adds basic AGENTS.md

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

This comment has been minimized.

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

reviewfn Bot commented Jun 16, 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 function, secret, store, template, namespace, log, and version commands.
  • Adds tests for selected JSON output and TLS warning behavior.
  • Updates Docker GitHub Actions versions and the Docker build image version.
  • Adds AGENTS.md with repository guidance for agent-based contributors.
  • Most JSON paths are straightforward marshal-and-print conversions over existing response structs.
  • The namespace JSON path still has stdout contamination and command coverage gaps.

Approval rating (1-10)

7/10. The feature is useful, but namespace JSON output needs fixes before it is reliable across supported namespace-listing entry points.

Summary per file

Summary per file
File path Summary
.github/workflows/build.yaml Bumps Docker setup and build action versions.
.github/workflows/publish.yaml Bumps Docker setup, login, and build action versions.
AGENTS.md Adds agent contribution guidance for the repository.
Dockerfile Bumps builder image from Go 1.25 to Go 1.26.
commands/describe.go Adds JSON output for function descriptions.
commands/generate.go Reindents Cobra examples.
commands/json_output_test.go Adds tests for JSON stdout and TLS warning behavior.
commands/list.go Adds JSON output for function lists.
commands/logs.go Adds --json alias for JSON log formatting.
commands/namespaces_list.go Adds JSON output for namespace list.
commands/plugin_get.go Reindents Cobra examples.
commands/publish.go Reindents Cobra examples.
commands/ready.go Reindents Cobra examples.
commands/secret_generate.go Adds gen alias and omits newline when piped.
commands/secret_list.go Adds JSON output for secret lists.
commands/secret_remove.go Reindents Cobra examples.
commands/secret_unseal.go Adds JSON output for unsealed secrets.
commands/secret_update.go Reindents Cobra examples.
commands/store_describe.go Adds JSON output for store function details.
commands/store_list.go Adds JSON output for store function lists.
commands/template_store_describe.go Adds JSON output for template details.
commands/template_store_list.go Adds JSON output for template lists.
commands/version.go Adds structured JSON version output.

Overall Assessment

The implementation mostly follows the existing command structure and keeps the text output paths intact. The main issue is that namespace JSON support is incomplete: namespace list --json can still emit non-JSON text before the JSON payload, and the older top-level namespaces listing command does not accept the new flag. I could not run the Go tests because the go binary is not installed in this environment.

Detailed Review

Detailed Review

Findings

Medium: namespace list --json can emit auth lookup text before the JSON payload

commands/namespaces_list.go:44-54 calls GetDefaultSDKClient() before printing JSON. That helper currently writes Failed to lookup auth config: ... to stdout when no CLI auth config exists, even if the user supplies --token. With this PR, a common first-run command such as faas-cli namespace list --json --token "$TOKEN" can produce stdout like:

Failed to lookup auth config: ...
[
  "openfaas-fn"
]

That breaks the primary contract of --json, because stdout is no longer parseable JSON. The new tests cover TLS warning suppression for some JSON commands, but this namespace path has a different stdout contaminant.

Route auth lookup warnings to stderr, suppress expected missing-config errors when a token is provided, or make GetDefaultSDKClient() return the warning so runNamespaces can avoid writing any non-JSON stdout when jsonOutput is set.

Medium: The existing top-level namespaces list command does not get --json

commands/namespaces_list.go:14-17 registers the new JSON flag only on namespaceListCmd, while the same file still exposes the older top-level namespaces command at commands/namespaces_list.go:20-30 and routes it through the same runNamespaces function. As a result, faas-cli namespace list --json works, but faas-cli namespaces --json fails with an unknown flag even though both commands list namespaces.

This is inconsistent with the PR goal of adding structured output to get/list commands and leaves an existing namespace-listing entry point behind. Add the same --json flag to namespacesCmd, or make namespaces an alias/subcommand path that shares the flag behavior.

AI agent details.

Agent processing time: 3m3.027s
Environment preparation time: 12.018s
Total time from webhook: 3m26.851s

@alexellis alexellis merged commit 4635619 into master Jun 16, 2026
3 checks passed
@alexellis alexellis deleted the json_flag branch June 16, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant