feat(test): document required positional args and use cobra.ExactArgs#447
Open
hazelmayank wants to merge 1 commit into
Open
feat(test): document required positional args and use cobra.ExactArgs#447hazelmayank wants to merge 1 commit into
hazelmayank wants to merge 1 commit into
Conversation
Signed-off-by: hazelmayank <mayankjeefinal@gmail.com>
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.
Summary
Make
microcks test --helpself-documenting and replace the manualarg-count check with Cobra's declarative
Args: cobra.ExactArgs(3).Fixes #446 .
Background
microcks test --helppreviously showed:…with no indication that three positional arguments are required. The contract
was only discoverable by running the command with no args and reading the
error printed by a manual
if len(os.Args) < 4check in theRunbody.Changes
cmd/test.go:Document the positional args in Cobra metadata.
Use:is nowtest <apiName:apiVersion> <testEndpoint> <runner>.Long:describes each required argument and the runner choices.Example:block shows a realistic invocation including theKeycloak service-account flags used in CI.
Use Cobra's declarative arg validation.
Args: cobra.ExactArgs(3)is set on the command. Cobra now rejectswrong-arg-count invocations with a usage hint, before the
Runbody even fires.
if len(os.Args) < 4 { ... os.Exit(1) }block in
Run.The per-argument empty-string and dash-prefix checks are intentionally kept
as defense-in-depth.
No change to flags, server interaction, exit codes for the valid path,
or the runner-validation behavior.
Before / after
Before:
After:
Test plan
go build .passes.microcks test --helpshows the new docs.microcks test(no args) prints Cobra's "accepts 3 arg(s), received 0"with the new Usage hint, and exits non-zero.
microcks test a b c d(4 args) is rejected with "accepts 3 arg(s),received 4".