Skip to content

fix: human output honors default_fields; --schema reports when none registered#23

Open
jpage-godaddy wants to merge 5 commits into
mainfrom
fix-human-fields
Open

fix: human output honors default_fields; --schema reports when none registered#23
jpage-godaddy wants to merge 5 commits into
mainfrom
fix-human-fields

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

What & why

Two output-discoverability fixes that surfaced while building a consumer CLI.

1. Human output honors default_fields

Previously the human (table) renderer ignored a command's default_fields and dumped every column, while json/toon honored it. A command with a curated default_fields (e.g. domain,status,expires) still produced a 15+ column wall in an interactive terminal.

Now default_fields applies in every output format. The one exception: a command with a registered HumanView — that view selects its own columns from the full payload, so pre-projecting would strip fields it needs. Those commands are unchanged.

Full data is always one flag away: --fields all / --fields '*' / --output json.

2. --schema reports when no schema is registered

Previously --schema on a command with no registered output schema silently fell through and ran the command — surprising and easy to mistake for a broken flag. It now returns a clear message instead of executing the command:

No output schema is registered for this command.

(The message intentionally does not suggest "run it with --fields all": --schema must not execute the command — that would run a mutation.)

Changes

  • src/middleware.rs — apply default_fields in human mode unless a HumanView is registered for the command's system; emit a no-schema message instead of falling through.
  • src/output/human.rs — add HumanViewRegistry::has_view.
  • tests/ — cover human projection (with the registered-view exception) and the no-schema --schema message. Also corrected an existing registered-views test that registered its view under a non-matching schema_id, so it now actually exercises the view path.

Verification

cargo fmt --check, cargo clippy --all-targets -- -D warnings, and cargo test all clean.

🤖 Generated with Claude Code

…registered

Human (table) output previously ignored a command's default_fields and dumped
every column. It now applies default_fields in every format — json, toon, and
human — so an interactive table shows the curated columns. The one exception is
a command with a registered HumanView: that view selects its own columns from
the full payload, so projecting first would strip fields it needs. Full data is
always one flag away via `--fields all` / `--output json`.

`--schema` previously fell through and ran the command when no output schema was
registered, which was confusing. It now returns a clear message pointing at
`--fields all` instead of executing the command.

Adds HumanViewRegistry::has_view and tests for both behaviors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves output discoverability and consistency in the CLI engine by (1) making human/table output honor a command’s default_fields (matching existing behavior in JSON output) and (2) making --schema reliably short-circuit with a clear message when no schema is registered, instead of silently running the command.

Changes:

  • Apply default_fields field projection to Human output, except when a registered HumanView exists for the command’s schema/system (to avoid stripping fields the view needs).
  • Make --schema always short-circuit; when no schema is registered, return a JSON envelope containing a clear “no schema registered” message and a hint to use --fields all / --output json.
  • Add/adjust tests to cover human projection behavior (including the registered-view exception) and the new --schema no-schema message path.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/middleware.rs Implements schema short-circuit messaging and updates field selection logic to apply default_fields in Human output except when a HumanView is registered.
src/output/human.rs Adds HumanViewRegistry::has_view to allow middleware to detect registered views and avoid pre-projection.
tests/foundation.rs Adds coverage for --schema with no schema registered and fixes a registered-view test to register under the resolved system id.
tests/consumer_cli.rs Adds integration-style tests verifying Human output respects default_fields, and that --fields all overrides it.

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

…essage

The second sentence suggested "run it with --fields all", but --schema is meant
NOT to run the command — and that advice would execute a mutation. Keep the
message to the accurate first sentence.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread tests/foundation.rs
Comment thread src/middleware.rs
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/middleware.rs Outdated
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/middleware.rs
Return `{command, fields: []}` (plus an additive `message`) so consumers can
parse the registered and unregistered cases uniformly, instead of the previous
`{command, schema: null, message}`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@jpage-godaddy jpage-godaddy changed the title feat: human output honors default_fields; --schema reports when none registered fix: human output honors default_fields; --schema reports when none registered Jun 15, 2026
@jbrooks2-godaddy

Copy link
Copy Markdown
Collaborator

A bit out of my depth on the specific changes here, still need to learn more about the internals of cli-engine to properly review. Two edge case issues flagged by my agents, I think they're reasonable concerns but take with a grain of salt:

  • Public Cli::run path still does not return the no-schema response when required args are missing.
    The fix is in middleware, but src/cli.rs (line 1462) only bypasses clap parsing when a schema is found. If no schema exists, it returns None, then clap validates the command. For a no-schema command with required args, like project delete --id in tests/consumer_cli.rs (line 53), my-cli project delete --schema --output json reports missing --id instead of No output schema is registered for this command. The new test hits Middleware::run_no_auth directly, so it misses the public CLI behavior.

  • HumanView exception only checks system, but documented views can be keyed by command path.
    The exception uses self.human_views.has_view(&system) in src/middleware.rs (line 956), then renders with the same system key. Docs say views can be keyed by command path or schema id, e.g. docs/concepts.md (line 523), and the consumer example registers project:list in tests/consumer_cli.rs (line 25). For commands with .with_system("projects-api"), that command-path view is not detected, so default-field projection can still run before the view gets full data. Either support command-path lookup here, or tighten docs/examples to system-only keys.

Suggested Tests
Add a Cli::run integration test for --schema on an unregistered command with missing required args. Add a human-view regression where the view is registered as command:path, needs a field outside default_fields, and output stays unprojected.

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.

4 participants