Skip to content

fix: only register --reason when authz/auditor/activity is configured - #50

Merged
jpage-godaddy merged 3 commits into
mainfrom
optional-reason-flag
Jul 16, 2026
Merged

fix: only register --reason when authz/auditor/activity is configured#50
jpage-godaddy merged 3 commits into
mainfrom
optional-reason-flag

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • --reason was registered unconditionally by register_global_flags, with help text claiming it was "required for destructive commands." Nothing enforced or read that value unless an app had wired an Authorizer, Auditor, or ActivityEmitter — apps without any of those (e.g. the base gddy CLI) got a flag that was captured and silently discarded (DEVEX-884).
  • Split --reason registration out into a new register_reason_flag, called conditionally in Cli::new when config.authz/auditor/activity is set — mirroring the existing config.environments.is_some() conditional right below it.
  • Fixed global_flags_from_matches to read "reason" via try_get_one instead of get_one: clap's get_one panics (not just returns None) for an arg id that was never registered on the Command at all, which is now the case for apps that don't configure authz/auditor/activity.
  • Updated docs/design.md and docs/concepts.md to note the flag is conditional, and that it's gated on CliConfig's eager authz/auditor/activity fields specifically — an authorizer/auditor/activity emitter wired later via init_deps (which runs per-request, after flag registration) does not register --reason (refined during review).
  • Help text for --reason now mentions all three consumers (authorizer, auditor, activity emitter), not just the first two (refined during review).
  • Added an integration test (reason_flag_is_registered_only_when_authz_auditor_or_activity_is_configured) asserting --reason is a clap usage error (exit code 2) with none of the three configured, and parses successfully once authz is set (added during review).

Test plan

  • cargo fmt --all --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --all-targets

Manual verification

Build a throwaway Cli with no authz/auditor/activity and confirm --help no longer lists --reason; build one with .with_authz(...) and confirm it does.

--reason was registered on every app and claimed to be "required for
destructive commands," but nothing enforced or read it unless the app
had wired an Authorizer, Auditor, or ActivityEmitter. Apps with none
of those configured got a flag that was captured and silently
discarded.

register_reason_flag is now called conditionally in Cli::new, gated
on config.authz/auditor/activity, mirroring the existing
config.environments.is_some() pattern.

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 updates cli_engine’s global flag registration so --reason is only exposed when it can be meaningfully consumed (authz/audit/activity), and avoids clap panics when the flag is not registered.

Changes:

  • Split --reason registration into register_reason_flag and register it conditionally in Cli::new.
  • Updated global flag extraction to use try_get_one("reason") to avoid panics when --reason is not registered.
  • Updated tests and docs to reflect that --reason is conditional.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/foundation.rs Adjusts tests to account for --reason no longer being always present; updates one command builder test to explicitly register the reason flag.
tests/exhaustive_public_api.rs Updates the “common args” command builder to include register_reason_flag so API surface tests cover it.
src/lib.rs Re-exports register_reason_flag from the crate root.
src/flags.rs Removes unconditional --reason registration; adds register_reason_flag; makes global_flags_from_matches resilient when the arg isn’t registered.
src/cli.rs Conditionally registers --reason during CLI construction based on configured authz/auditor/activity hooks.
docs/design.md Documents that --reason is only registered when relevant hooks are configured.
docs/concepts.md Documents the conditional presence of --reason and its intended use.

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

Comment thread src/cli.rs
Comment thread src/flags.rs Outdated
Comment thread tests/foundation.rs
Copilot review on #50 raised three points:

- --reason help text said it's forwarded to "your authorizer/auditor"
  but omitted the activity emitter, which also consumes it.
- The authz/auditor/activity gate in Cli::new only sees CliConfig's
  eager fields, not an authorizer/auditor/activity wired later through
  init_deps (which runs per-request, after flag registration). Made
  this explicit in doc comments and docs/{design,concepts}.md rather
  than changing the gating itself, since inspecting init_deps at
  registration time isn't possible.
- Added an integration test asserting --reason is an unknown argument
  with no authz/auditor/activity configured, and parses successfully
  once one is.

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 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/foundation.rs Outdated
exit_code != 0 could pass for any failure, not specifically an unknown
--reason argument. Cli::run forwards clap parse errors via
err.exit_code(), which is clap's USAGE_CODE (2) for an unrecognized
argument — assert that specific code instead.

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 7 out of 7 changed files in this pull request and generated no new comments.

@jpage-godaddy
jpage-godaddy merged commit 81f50b1 into main Jul 16, 2026
4 checks passed
@jpage-godaddy
jpage-godaddy deleted the optional-reason-flag branch July 16, 2026 16:25
jpage-godaddy pushed a commit that referenced this pull request Jul 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.4.4](cli-engine-v0.4.3...cli-engine-v0.4.4)
(2026-07-16)


### Features

* **auth:** add scopes tracking, extensible auth commands, standalone
module walk ([#49](#49))
([bebe5bb](bebe5bb))


### Bug Fixes

* only register --reason when authz/auditor/activity is configured
([#50](#50))
([81f50b1](81f50b1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants