Fix JSON output for rad app graph command#11207
Fix JSON output for rad app graph command#11207brooke-hamilton merged 4 commits intoradius-project:mainfrom
Conversation
Allows rad app graph command to output json Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
There was a problem hiding this comment.
Pull request overview
Enables rad app graph to honor -o json by adding the shared output flag and emitting structured output for JSON format, aligning the command with other CLI commands that support --output.
Changes:
- Add
--output/-osupport torad app graphand plumb the selected format into the runner. - When
-o jsonis selected, write the rawApplicationGraphResponseviaWriteFormatted. - Add a unit test covering JSON output behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/cli/cmd/app/graph/graph.go | Adds output flag support and JSON formatted output path for rad app graph. |
| pkg/cli/cmd/app/graph/graph_test.go | Adds a new test ensuring JSON format uses WriteFormatted. |
| format, err := cli.RequireOutput(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| r.Format = format | ||
|
|
There was a problem hiding this comment.
The output format read from the flag is never validated/normalized. If a user passes an unsupported value (or a different casing like -o JSON), Run() will silently fall back to the table-style display instead of returning an error / emitting JSON. Normalize the flag value (trim/lowercase) and validate it against output.SupportedFormats() (or use output.NewFormatter for validation) during Validate(), then switch on the normalized value in Run().
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
brooke-hamilton
left a comment
There was a problem hiding this comment.
Only one nit: please update the PR title to something descriptive like "Fix JSON output for rad app graph command"
The rad app graph -o json command works well:
$ rad app graph --output json | jq
{
"resources": [
{
"connections": [],
"id": "/planes/radius/local/resourcegroups/default/providers/Applications.Core/containers/demo",
"name": "demo",
"outputResources": [
{
"id": "/planes/kubernetes/local/namespaces/default-testfix/providers/apps/Deployment/demo",
"name": "demo",
"type": "apps/Deployment"
},
{
"id": "/planes/kubernetes/local/namespaces/default-testfix/providers/core/Service/demo",
"name": "demo",
"type": "core/Service"
},
{
"id": "/planes/kubernetes/local/namespaces/default-testfix/providers/core/ServiceAccount/demo",
"name": "demo",
"type": "core/ServiceAccount"
},
{
"id": "/planes/kubernetes/local/namespaces/default-testfix/providers/rbac.authorization.k8s.io/Role/demo",
"name": "demo",
"type": "rbac.authorization.k8s.io/Role"
},
{
"id": "/planes/kubernetes/local/namespaces/default-testfix/providers/rbac.authorization.k8s.io/RoleBinding/demo",
"name": "demo",
"type": "rbac.authorization.k8s.io/RoleBinding"
}
],
"provisioningState": "Succeeded",
"type": "Applications.Core/containers"
}
]
}| return err | ||
| } | ||
| r.Format = format | ||
|
|
There was a problem hiding this comment.
+1 to what Copilot said: the format command falls back to text when the output is invalid. Other commands validate the input. Here's an example:
# This command fails silently.
$ rad app graph --output banana
Displaying application: testfix
Name: demo (Applications.Core/containers)
Connections: (none)
Resources:
demo (apps/Deployment)
demo (core/Service)
demo (core/ServiceAccount)
demo (rbac.authorization.k8s.io/Role)
demo (rbac.authorization.k8s.io/RoleBinding)
# This command fails as expected.
$ rad app list --output banana
Error: unsupported format banana
TraceId: a44b8eb4a8f8aa693d96b8ffae79d59f
There was a problem hiding this comment.
$ rad app graph -o banana
unsupported output format "banana", supported formats are: json, table, plain-text|
@copilot open a new pull request to apply changes based on the comments in this thread |
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
Radius functional test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
Allows rad app graph command to output json (Please note I am very new to Go development and welcome feedback on things I can improve!) # Description Fixes bug where `rad app graph -o json` was not outputting json. ## Type of change <!-- Please select **one** of the following options that describes your change and delete the others. Clearly identifying the type of change you are making will help us review your PR faster, and is used in authoring release notes. If you are making a bug fix or functionality change to Radius and do not have an associated issue link please create one now. --> - This pull request fixes a bug in Radius and has an approved issue (issue link required). (Not necessarily approved, but I filed issue #11205 before filing this pull request) <!-- Please update the following to link the associated issue. This is required for some kinds of changes (see above). --> Fixes: #11205 ## Contributor checklist Please verify that the PR meets the following requirements, where applicable: <!-- This checklist uses "TaskRadio" comments to make certain options mutually exclusive. See: https://github.com/mheap/require-checklist-action?tab=readme-ov-file#radio-groups For details on how this works and why it's required. --> - An overview of proposed schema changes is included in a linked GitHub issue. - [ ] Yes <!-- TaskRadio schema --> - [x] Not applicable <!-- TaskRadio schema --> - A design document PR is created in the [design-notes repository](https://github.com/radius-project/design-notes/), if new APIs are being introduced. - [ ] Yes <!-- TaskRadio design-pr --> - [x] Not applicable <!-- TaskRadio design-pr --> - The design document has been reviewed and approved by Radius maintainers/approvers. - [ ] Yes <!-- TaskRadio design-review --> - [x] Not applicable <!-- TaskRadio design-review --> - A PR for the [samples repository](https://github.com/radius-project/samples) is created, if existing samples are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio samples-pr --> - [x] Not applicable <!-- TaskRadio samples-pr --> - A PR for the [documentation repository](https://github.com/radius-project/docs) is created, if the changes in this PR affect the documentation or any user facing updates are made. - [ ] Yes <!-- TaskRadio docs-pr --> - [x] Not applicable <!-- TaskRadio docs-pr --> - A PR for the [recipes repository](https://github.com/radius-project/recipes) is created, if existing recipes are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio recipes-pr --> - [x] Not applicable <!-- TaskRadio recipes-pr --> --------- Signed-off-by: Nell Shamrell <nellshamrell@gmail.com> Co-authored-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com>
Allows rad app graph command to output json (Please note I am very new to Go development and welcome feedback on things I can improve!) # Description Fixes bug where `rad app graph -o json` was not outputting json. ## Type of change <!-- Please select **one** of the following options that describes your change and delete the others. Clearly identifying the type of change you are making will help us review your PR faster, and is used in authoring release notes. If you are making a bug fix or functionality change to Radius and do not have an associated issue link please create one now. --> - This pull request fixes a bug in Radius and has an approved issue (issue link required). (Not necessarily approved, but I filed issue #11205 before filing this pull request) <!-- Please update the following to link the associated issue. This is required for some kinds of changes (see above). --> Fixes: #11205 ## Contributor checklist Please verify that the PR meets the following requirements, where applicable: <!-- This checklist uses "TaskRadio" comments to make certain options mutually exclusive. See: https://github.com/mheap/require-checklist-action?tab=readme-ov-file#radio-groups For details on how this works and why it's required. --> - An overview of proposed schema changes is included in a linked GitHub issue. - [ ] Yes <!-- TaskRadio schema --> - [x] Not applicable <!-- TaskRadio schema --> - A design document PR is created in the [design-notes repository](https://github.com/radius-project/design-notes/), if new APIs are being introduced. - [ ] Yes <!-- TaskRadio design-pr --> - [x] Not applicable <!-- TaskRadio design-pr --> - The design document has been reviewed and approved by Radius maintainers/approvers. - [ ] Yes <!-- TaskRadio design-review --> - [x] Not applicable <!-- TaskRadio design-review --> - A PR for the [samples repository](https://github.com/radius-project/samples) is created, if existing samples are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio samples-pr --> - [x] Not applicable <!-- TaskRadio samples-pr --> - A PR for the [documentation repository](https://github.com/radius-project/docs) is created, if the changes in this PR affect the documentation or any user facing updates are made. - [ ] Yes <!-- TaskRadio docs-pr --> - [x] Not applicable <!-- TaskRadio docs-pr --> - A PR for the [recipes repository](https://github.com/radius-project/recipes) is created, if existing recipes are affected by the changes in this PR. - [ ] Yes <!-- TaskRadio recipes-pr --> - [x] Not applicable <!-- TaskRadio recipes-pr --> --------- Signed-off-by: Nell Shamrell <nellshamrell@gmail.com> Co-authored-by: Brooke Hamilton <45323234+brooke-hamilton@users.noreply.github.com> Signed-off-by: Will Tsai <28876888+willtsai@users.noreply.github.com>
Allows rad app graph command to output json
(Please note I am very new to Go development and welcome feedback on things I can improve!)
Description
Fixes bug where
rad app graph -o jsonwas not outputting json.Type of change
Fixes: #11205
Contributor checklist
Please verify that the PR meets the following requirements, where applicable: