-
-
Notifications
You must be signed in to change notification settings - Fork 23
ADding --json flag to CLI commands #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 pull request adds a global --json flag to CLI commands to enable structured JSON output across the devtui tool. The PR consolidates previously command-specific JSON flags into a unified, persistent flag on the root command and adds JSON output support to 18 additional commands.
Changes:
- Introduces a new
json_output.gofile with a centralizedwriteJSONValue()helper function for consistent JSON output handling - Adds a persistent
--jsonflag to the root command that is available to all subcommands - Migrates existing commands (numbers, uuiddecode) from command-specific JSON flags to the global flag
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cmd/json_output.go | New file providing shared JSON output functionality with writeJSONValue() helper |
| cmd/root.go | Adds persistent --json flag to root command |
| cmd/yaml2toml.go | Adds JSON output support for YAML to TOML conversion |
| cmd/xmlfmt.go | Adds JSON output support for XML formatting |
| cmd/version.go | Adds JSON output support for version information |
| cmd/uuiddecode.go | Removes local --json flag declaration, migrates to global flag |
| cmd/urls.go | Adds JSON output support for URL extraction |
| cmd/tsv2md.go | Adds JSON output support for TSV to Markdown conversion |
| cmd/tomlfmt.go | Adds JSON output support for TOML formatting |
| cmd/toml2yaml.go | Adds JSON output support for TOML to YAML conversion |
| cmd/numbers.go | Removes local --json flag declaration, migrates to global flag |
| cmd/jsonfmt.go | Minor whitespace cleanup (blank line removal) |
| cmd/json2yaml.go | Adds JSON output support for JSON to YAML conversion |
| cmd/json2xml.go | Adds JSON output support for JSON to XML conversion |
| cmd/json2toon.go | Adds JSON output support for JSON to TOON conversion |
| cmd/json2toml.go | Adds JSON output support for JSON to TOML conversion |
| cmd/iban.go | Adds JSON output support for IBAN generation |
| cmd/gqlquery.go | Adds JSON output support for GraphQL query formatting |
| cmd/csv2md.go | Adds JSON output support for CSV to Markdown conversion |
| cmd/cssmin.go | Adds JSON output support for CSS minification |
| cmd/cssfmt.go | Adds JSON output support for CSS formatting |
| cmd/count.go | Adds JSON output support for text statistics |
| cmd/base64.go | Adds JSON output support for base64 encoding/decoding |
| cmd/uuiddecode_test.go | Updates tests to use global outputJSON variable |
| cmd/numbers_test.go | Updates tests to use global outputJSON variable |
Comments suppressed due to low confidence (2)
cmd/uuiddecode.go:63
- The
uuiddecodecommand should be updated to use the newwriteJSONValuehelper function instead ofjson.MarshalIndentfor consistency with other commands in this PR. The current implementation bypasses the centralized JSON output logic, which defeats the purpose of having a shared helper function.
if outputJSON {
payload := uuidDecodeJSON{
UUID: parsed.String(),
Fields: fields,
}
bytes, err := json.MarshalIndent(payload, "", " ")
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(bytes))
return err
cmd/numbers.go:56
- The
numberscommand should be updated to use the newwriteJSONValuehelper function instead ofjson.MarshalIndentfor consistency with other commands in this PR. The current implementation bypasses the centralized JSON output logic, which defeats the purpose of having a shared helper function.
if outputJSON {
bytes, err := json.MarshalIndent(result, "", " ")
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(bytes))
return err
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func writeJSONValue(out io.Writer, value any) error { | ||
| encoder := json.NewEncoder(out) | ||
| encoder.SetEscapeHTML(false) |
Copilot
AI
Feb 1, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The writeJSONValue function uses json.NewEncoder which produces compact (non-indented) JSON output. However, the uuiddecode and numbers commands previously used json.MarshalIndent with 2-space indentation. This creates an inconsistency where these two commands now produce compact JSON while they previously produced indented JSON.
Consider either:
- Using
encoder.SetIndent("", " ")inwriteJSONValueto produce indented output consistently across all commands, or - Updating
uuiddecode.goandnumbers.goto also usewriteJSONValueso all commands have the same compact JSON format
Option 1 is generally preferred for CLI tools as it makes the JSON output more human-readable.
| encoder.SetEscapeHTML(false) | |
| encoder.SetEscapeHTML(false) | |
| encoder.SetIndent("", " ") |
This is preferred format of interaction with MCP's.