Skip to content

Conversation

@skatkov
Copy link
Owner

@skatkov skatkov commented Feb 1, 2026

This is preferred format of interaction with MCP's.

Copy link

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 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.go file with a centralized writeJSONValue() helper function for consistent JSON output handling
  • Adds a persistent --json flag 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 uuiddecode command should be updated to use the new writeJSONValue helper function instead of json.MarshalIndent for 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 numbers command should be updated to use the new writeJSONValue helper function instead of json.MarshalIndent for 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)
Copy link

Copilot AI Feb 1, 2026

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:

  1. Using encoder.SetIndent("", " ") in writeJSONValue to produce indented output consistently across all commands, or
  2. Updating uuiddecode.go and numbers.go to also use writeJSONValue so 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.

Suggested change
encoder.SetEscapeHTML(false)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")

Copilot uses AI. Check for mistakes.
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