clasp icon indicating copy to clipboard operation
clasp copied to clipboard

feat: Add global --json flag for commands

Open sqrrrl opened this issue 6 months ago • 0 comments

This change introduces a global --json flag to provide command output in a machine-readable JSON format.

Key changes:

  • Added a global --json option in src/commands/program.ts.
  • Removed local --json flags from src/commands/show-file-status.ts and src/commands/tail-logs.ts.
  • Updated all commands to utilize the global --json flag and output appropriate JSON structures when the flag is present.
    • For commands that output lists of items (e.g., list-scripts, list-deployments), the JSON output is an object containing an array of those items.
    • For commands that perform actions (e.g., create-script, deploy), the JSON output includes relevant identifiers (like scriptId, deploymentId, version) or status messages.
    • For commands that open URLs, the JSON output is {"url": "openedUrl"} and the URL is still opened in the browser.
    • Informational text messages are suppressed when --json is active.
  • Updated or created unit tests for all commands to ensure:
    • Correct JSON output when the --json flag is used.
    • Continued correct behavior for standard text output.
    • Proper mocking of dependencies and use of the runCommand utility.
    • Verification that text output is suppressed when JSON output is active.

Fixes #<issue_number_goes_here> (it's a good idea to open an issue first for discussion)

  • [ ] npm run test succeeds.
  • [ ] npm run lint succeeds.
  • [ ] Appropriate changes to README are included in PR.

sqrrrl avatar Jun 13 '25 01:06 sqrrrl