fix(cli): exit 2 for arg-count misuse on review submit and preview#2393
Open
abhay-codes07 wants to merge 1 commit into
Open
fix(cli): exit 2 for arg-count misuse on review submit and preview#2393abhay-codes07 wants to merge 1 commit into
abhay-codes07 wants to merge 1 commit into
Conversation
The usageError convention (AGENTS.md) requires CLI misuse to exit 2 and runtime/daemon failures to exit 1. `ao review submit` and `ao preview` declared their positional-arg validators as a bare cobra.MaximumNArgs(1) (and `preview clear` as cobra.NoArgs), whose validation error is a plain cobra error, not a usageError. Passing too many positional args therefore exited 1 instead of 2 — inconsistent with every other command (noArgs, oneSessionIDArg, project, completion) and with these commands' own usage-error tests, which already assert exit 2 for other misuse. Wrap the validators so arg-count misuse returns usageError (exit 2), and reuse the existing noArgs helper for `preview clear`. Add tests covering the too-many-args path for review submit, preview, and preview clear.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2391.
What
ao review submitandao preview(andao preview clear) exited1instead of2when given too many positional args, breaking theusageError→ exit-2 convention in AGENTS.md ("Return usage errors asusageErrorso CLI misuse exits 2; runtime/daemon failures should exit 1.").Why
Their
Argsvalidators were a barecobra.MaximumNArgs(1)/cobra.NoArgs. Cobra's arg-count error is a plain error, and the root'sSetFlagErrorFunconly wraps flag-parse errors asusageError— notArgsvalidation — soExitCodereturned 1. Every other command wraps its validator (noArgs,oneSessionIDArg, the inline wrappers inproject.go/completion.go).Change
Wrap the validators so arg-count misuse returns
usageError(exit 2), and reuse the existingnoArgshelper forpreview clear.Tests
TestReviewSubmitTooManyArgsIsUsageError,TestPreview_TooManyArgsIsUsageError, andTestPreviewClear_TooManyArgsIsUsageError. Each fails before the change (exit 1) and passes after (exit 2).go test ./internal/cli/...green;go vetand gofmt clean.cc @harshitsinghbhandari — matches the existing usage-error tests on these commands; happy to tweak.