Skip to content

feat(phase-2): add output format selection and auto mode#77

Merged
overtrue merged 1 commit intomainfrom
codex/phase-2-agent-output-modes
Apr 1, 2026
Merged

feat(phase-2): add output format selection and auto mode#77
overtrue merged 1 commit intomainfrom
codex/phase-2-agent-output-modes

Conversation

@overtrue
Copy link
Copy Markdown
Contributor

@overtrue overtrue commented Apr 1, 2026

Summary

  • add global --format auto|human|json selection while keeping the legacy --json flag
  • introduce terminal-aware output resolution that disables colors and progress automatically in non-TTY contexts
  • make the new noun-first bucket and object command groups default to auto output selection while legacy commands keep human-readable defaults

Validation

  • cargo fmt --all
  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace

Notes

  • bucket and object now default to structured output when stdout is not a TTY
  • legacy flat commands continue to default to human-readable output unless --json or --format is provided
  • raw content commands such as cat and head keep their existing stdout semantics

Next phase

  • enrich machine-readable error output with typed fields and repair suggestions
  • add example-first help for the highest-value mutating commands
  • extend dry-run and idempotent/upsert-style flows for bucket mutations

@overtrue overtrue marked this pull request as ready for review April 1, 2026 10:58
Copilot AI review requested due to automatic review settings April 1, 2026 10:58
@overtrue overtrue merged commit 731e813 into main Apr 1, 2026
15 checks passed
@overtrue overtrue deleted the codex/phase-2-agent-output-modes branch April 1, 2026 10:58
Copy link
Copy Markdown
Contributor

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

Adds a global output-format selection mechanism to the Rust CLI, introducing an auto mode that adapts output behavior to TTY/non-TTY environments while preserving legacy --json usage and maintaining existing semantics for raw-content commands.

Changes:

  • Introduces global --format auto|human|json and centralizes output resolution (TTY-aware color/progress + JSON selection).
  • Updates command execution wiring so noun-first bucket/object default to auto/structured behavior, while legacy flat commands retain human defaults.
  • Extends the CLI help contract tests to require discoverability of the new global option.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/cli/src/commands/mod.rs Adds OutputFormat + TTY-aware resolution and applies per-command default output behavior during dispatch.
crates/cli/tests/help_contract.rs Ensures --format appears as a discoverable global option across --help outputs.

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

Comment on lines 55 to 56
/// Output format: human-readable or JSON
#[arg(long, global = true, default_value = "false")]
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

--json and --format can both be provided, and --json silently wins (selected_format forces Json when self.json is true). This is ambiguous UX and can mask mistakes in scripts/wrappers. Consider making them mutually exclusive via clap (conflicts_with = "format" / overrides_with = "format"), and/or update the --json help text to explicitly state it is a legacy alias that overrides --format.

Suggested change
/// Output format: human-readable or JSON
#[arg(long, global = true, default_value = "false")]
/// Legacy alias for `--format json` (mutually exclusive with `--format`)
#[arg(long, global = true, default_value = "false", conflicts_with = "format")]

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 08f8d42405

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +262 to +267
let behavior = match &args.command {
object::ObjectCommands::Show(_) | object::ObjectCommands::Head(_) => {
OutputBehavior::HumanDefault
}
_ => OutputBehavior::StructuredDefault,
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid auto-enabling JSON for non-JSON object dry-runs

Routing all object subcommands except show/head to StructuredDefault makes json=true whenever stdout is non-TTY, but several of those commands still print human dry-run text (for example, cp/mv/rm dry-run paths use formatter.println("Would ...") and return). In piped/CI usage, rc object copy|move|remove --dry-run now emits non-JSON output while auto mode has selected JSON, which breaks machine parsing and contradicts the new output-format contract.

Useful? React with 👍 / 👎.

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