Skip to content

feat(interactivity)!: let a command word its prompts and skip the missing-argument warning - #148

Open
jpage-godaddy wants to merge 2 commits into
mainfrom
recovery-prompt-copy
Open

jpage-godaddy wants to merge 2 commits into
mainfrom
recovery-prompt-copy

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • A guided command no longer opens with a warning. A command marked DefaultOnTty is meant to ask, so it now goes straight to its first question. Before, it printed ⚠ missing required argument(s): --provider-id, ... first, which reads like a mistake and made gddy domain-connect template init look broken. An ordinary command keeps the warning, since it was probably typed incompletely.
  • A command can word its own questions. CommandSpec::with_arg_prompt("provider-id", "Provider ID (your domain name)") sets the question for one arg. By default a question is the arg's --help sentence, which describes the flag and reads oddly as a question. The override applies to required args asked after a missing-argument error and to optional args named in with_prompted_args (which still get (optional)). --help and schema output don't change. Registration debug-asserts that the id names one of the command's args.
  • Prompter::notice (a default method) carries the warning, so a prompter can capture or restyle it and ScriptedPrompter::notices() returns it in a test, apart from the questions in transcript().
  • Smaller surface (breaking). The recovery and optional-prompt functions were pub, but nothing outside the engine calls them: run does. I collapsed their wrapper chains into one function each and made them, and the types they use, pub(crate). This follows the new note in AGENTS.md.

Follow-up to #140. It came from trying gddy domain-connect template init by hand on godaddy/cli#404.

Breaking change

Removed from cli_engine::prompt: try_recover_missing_args, try_recover_missing_args_with, prompt_optional_args, RecoveryResult and OptionalPromptResult. The first was public since 0.10.6 and the rest since 0.10.7. The engine calls all of them itself while running a command, and they have no use outside it. I searched the godaddy org (godaddy/cli and godaddy/cli-engine are the only repos that mention cli_engine::prompt), and the local gdx checkouts and cli-domain-connect use none of them. What consumers import from cli_engine::prompt is Answer, ScriptedPrompter, Prompter, TextValidator, prompt_repeat and prompt_confirm, and all of those stay. I can only vouch for repos I can see, so a private consumer would show up as a build break on upgrade. The PR is marked ! and carries a BREAKING CHANGE: footer, per CONTRIBUTING.md.

The wider cleanup of unneeded exports is tracked in DEVEX-1475.

Test plan

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • RUSTDOCFLAGS='-D warnings' cargo doc --no-deps
  • cargo test --workspace (970 pass)
  • New tests in tests/interactivity.rs: a guided command shows no notice and starts with its first question; an ordinary command keeps the warning; custom wording (trailing dot dropped, (optional) appended); the --help fallback; --help output unchanged by a custom prompt; and the registration assert. A unit test checks that a command's prompt settings are found past clustered short flags, option values and aliases, using the same argument-aware walk recovery uses. (refined during review)

Not covered by automated tests

The scripted prompter replaces the terminal, so how the prompts render on a real terminal isn't tested here. I haven't run this against a real terminal yet. The old behavior was checked on a pty during #140.

Manual verification

Setup: in the godaddy/cli repo, override the engine: [patch.crates-io] cli-engine = { path = "../../cli-engine/cli-engine" }, then cargo build.

Test WITHOUT the change: gddy domain-connect template init prints ⚠ missing required argument(s): --provider-id, --provider-name, --service-id, --service-name, then asks "Your domain name, which identifies you as the provider, e.g. acme.com:".

Test WITH the change (after init sets with_arg_prompt for its four flags): no warning, and the first line on screen is "Provider ID (your domain name):".

Cleanup: remove the [patch.crates-io] entry.

🤖 Generated with Claude Code

…sing-argument warning

A command marked DefaultOnTty is meant to ask, so it now goes straight to
its first question instead of printing a "missing required argument(s)"
warning first. A command can also set the question for any arg it prompts
for with CommandSpec::with_arg_prompt, instead of reusing the arg's --help
sentence, which describes the flag and reads oddly as a question.

- Add CommandSpec::with_arg_prompt. It applies to required args asked after
  a missing-argument error and to optional args named in with_prompted_args.
  --help and schema output are unchanged. Registration debug-asserts that
  the id names one of the command's args.
- Add Prompter::notice, a default method, so the warning goes through the
  prompter and a test prompter can record it (ScriptedPrompter::notices).
- Collapse the recovery and optional-prompt wrapper chains into one function
  each and narrow them, and the types they use, to pub(crate). Nothing
  outside the engine called them.
- Add a note to AGENTS.md to keep the public surface small.

BREAKING CHANGE: cli_engine::prompt no longer exports try_recover_missing_args,
try_recover_missing_args_with, prompt_optional_args, RecoveryResult or
OptionalPromptResult. The engine calls them itself while running a command,
so a consumer does not need them. No consumer we know of imports any of them.

Co-Authored-By: Claude Sonnet 5.5 <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.

🟡 Changes recommended

Clustered short flags can cause interactive recovery to ignore custom prompt settings, and the guide directs consumers to an inaccessible internal API.

2 open issues
What changed in this PR

This follow-up to #140 refines cli-engine’s guided prompting so commands can ask clearer questions without an unnecessary missing-argument warning.

Changes:

  • Adds per-argument prompt wording while preserving help and schema output.
  • Skips warnings for guided commands and makes notices capturable through Prompter.
  • Makes recovery helpers crate-private, with corresponding documentation and test updates.
File Description
cli-engine/​tests/​interactivity.rs Tests prompt wording, warnings, help stability, and registration validation.
cli-engine/​src/​prompt/​tests.rs Adapts recovery tests to internal prompt options.
cli-engine/​src/​prompt/​scripted.rs Records notices separately from questions.
cli-engine/​src/​prompt/​recovery.rs Applies custom wording and suppresses guided-command warnings.
cli-engine/​src/​prompt/​prompter.rs Adds the default notice method.
cli-engine/​src/​prompt/​options.rs Collects per-command prompting settings.
cli-engine/​src/​prompt/​optional.rs Applies custom wording to optional prompts.
cli-engine/​src/​prompt/​mod.rs Restricts recovery exports to crate scope.
cli-engine/​src/​command/​spec.rs Adds argument prompt storage and builder.
cli-engine/​src/​cli/​schema_tree.rs Validates prompt argument IDs during registration.
cli-engine/​src/​cli/​run.rs Passes command settings into prompting flows.
cli-engine/​src/​cli/​lookup.rs Looks up prompting settings by command path.
cli-engine/​docs/​concepts.md Documents prompt customization and notice behavior.
AGENTS.md Adds guidance on minimizing public APIs.

Review effort: Balanced

Comment thread cli-engine/src/cli/run.rs Resolved
Comment thread cli-engine/docs/concepts.md Resolved
…lk as recovery

The settings lookup used a cruder reading of argv than recovery itself, so a
clustered short flag before the command (for example -vv) could hide the
command from it and a guided command would lose its framing and custom
wording. Look the command up with the argument-aware walk that recovery
already uses, and drop the duplicate walker.

Also drop the docs sentence that pointed consumers at PromptOptions, which is
crate-private.

Co-Authored-By: Claude Sonnet 5.5 <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.

🟢 Approval recommended

No active review issues require resolution before approval.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
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