Skip to content

Improve UX and add JSON output#5

Merged
dylandreimerink merged 2 commits into
mainfrom
feature/ux-improvement
May 8, 2026
Merged

Improve UX and add JSON output#5
dylandreimerink merged 2 commits into
mainfrom
feature/ux-improvement

Conversation

@dylandreimerink
Copy link
Copy Markdown
Member

This PR merges the separate sub commands for collection and program listing into a singular list command for the sake of user experience.

This PR also adds JSON outputs to all commands to allow for usage in scripts or for data extraction.

The user experience of having a separate subcommands was suboptimal.
Specifically when a user does not know the names of all available
program in a collection. It is not easier to first run
`stackwhere list /path/to/collection.o` to get the list of programs, and
then append the program name to the command to get the stack listing of
a specific program.

We still keep this behind the `list` subcommand to allow for additional
features under different subcommands in the future.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR streamlines the CLI UX by consolidating the prior collection/program subcommands into a single list command, and introduces a global --json output mode to make command results script-friendly.

Changes:

  • Replace collection and program subcommands with a unified list {collection} [program] command.
  • Add a persistent --json / -j flag and JSON output support for list and version.
  • Update tests/docs to reflect the new command surface.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
README.md Updates usage examples/docs to the new list command.
cmd/stackwhere/main.go Adds persistent --json flag and registers only list + version.
cmd/stackwhere/version.go Adds JSON output mode for version and structures version info.
cmd/stackwhere/list.go Implements merged list behavior (collection summary vs program detail) and JSON output.
cmd/stackwhere/list_test.go Updates slot-usage test for exported fields; adds stack-usage test.
cmd/stackwhere/collection.go Removes deprecated collection subcommand implementation.
cmd/stackwhere/collection_test.go Removes deprecated collection test (moved/replaced elsewhere).
Comments suppressed due to low confidence (5)

cmd/stackwhere/list.go:62

  • --call-stack currently has no effect on JSON output: getStackSlotUsage always populates Callstack, and the JSON encoder emits it whenever non-empty even if the flag is false. Consider omitting/clearing Callstack (or computing it conditionally) unless --call-stack is enabled to keep JSON and text outputs consistent.
    cmd/stackwhere/list.go:71
  • Non-JSON output is written via fmt.Printf, which bypasses Cobra's configured output writer. Use cmd.OutOrStdout() (e.g., fmt.Fprintf(cmd.OutOrStdout(), ...) or cmd.Printf) so output can be redirected/captured consistently (including in tests).
    cmd/stackwhere/list.go:249
  • Sorting comparator returns only the stack-usage difference, but the comment says it also sorts by name. When two programs have equal stack_usage, slices.SortFunc may produce nondeterministic ordering; add a secondary name comparison (and avoid int64 subtraction -> int cast) to ensure a total order.
    cmd/stackwhere/list.go:275
  • Non-JSON output is printed with fmt.Printf, which ignores Cobra's output writer. Prefer writing to cmd.OutOrStdout() so users/tests can redirect output consistently.
    cmd/stackwhere/list.go:62
  • New JSON-output paths aren’t covered by tests. Adding a small test that runs the command with --json and asserts the output is valid JSON (and respects flags like --call-stack) would help prevent regressions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread cmd/stackwhere/version.go Outdated
Added global `--json`/`-j` flag and made every command output JSON when
the flag is set. The JSON output is pretty-printed for human inspection.
This allows stackwhere to be used in scripts and pipelines.

Signed-off-by: Dylan Reimerink <dylan.reimerink@isovalent.com>
@dylandreimerink dylandreimerink force-pushed the feature/ux-improvement branch from 15e9a00 to 1d976b6 Compare May 8, 2026 13:15
@dylandreimerink dylandreimerink merged commit 0f42f78 into main May 8, 2026
3 checks passed
@dylandreimerink dylandreimerink deleted the feature/ux-improvement branch May 8, 2026 13:16
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.

2 participants