这是indexloc提供的服务,不要输入任何密码
Skip to content

feat: Add global --json flag for commands #1070

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

Closed
wants to merge 1 commit into from

Conversation

sqrrrl
Copy link
Member

@sqrrrl sqrrrl commented Jun 13, 2025

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.

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.
@sqrrrl sqrrrl closed this Jul 22, 2025
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.

1 participant