Skip to content

feat(test): document required positional args and use cobra.ExactArgs#447

Open
hazelmayank wants to merge 1 commit into
microcks:masterfrom
hazelmayank:feat/test-cmd-document-positional-args
Open

feat(test): document required positional args and use cobra.ExactArgs#447
hazelmayank wants to merge 1 commit into
microcks:masterfrom
hazelmayank:feat/test-cmd-document-positional-args

Conversation

@hazelmayank
Copy link
Copy Markdown
Contributor

Summary

Make microcks test --help self-documenting and replace the manual
arg-count check with Cobra's declarative Args: cobra.ExactArgs(3).

Fixes #446 .

Background

microcks test --help previously showed:

Usage:
  microcks test [flags]

…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) < 4 check in the Run body.

Changes

cmd/test.go:

  1. Document the positional args in Cobra metadata.

    • Use: is now test <apiName:apiVersion> <testEndpoint> <runner>.
    • Long: describes each required argument and the runner choices.
    • New Example: block shows a realistic invocation including the
      Keycloak service-account flags used in CI.
  2. Use Cobra's declarative arg validation.

    • Args: cobra.ExactArgs(3) is set on the command. Cobra now rejects
      wrong-arg-count invocations with a usage hint, before the Run
      body even fires.
    • Removed the now-redundant 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:

Usage:
  microcks test [flags]

After:

Usage:
  microcks test <apiName:apiVersion> <testEndpoint> <runner> [flags]

Required arguments:
  <apiName:apiVersion>  Service reference, e.g. "Beer Catalog API:0.9".
  <testEndpoint>        URL of the deployed implementation under test.
  <runner>              Test strategy. One of: HTTP, SOAP_HTTP, SOAP_UI,
                        POSTMAN, OPEN_API_SCHEMA, ASYNC_API_SCHEMA,
                        GRPC_PROTOBUF, GRAPHQL_SCHEMA.

Examples:
  microcks test "Beer Catalog API:0.9" http://my-service/api/ POSTMAN \
    --microcksURL=http://microcks.example.com/api \
    --keycloakClientId=microcks-serviceaccount \
    --keycloakClientSecret=<secret> \
    --waitFor=10sec

Test plan

  • go build . passes.
  • microcks test --help shows 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".
  • CI passes on all platforms.

Signed-off-by: hazelmayank <mayankjeefinal@gmail.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.

test command help text does not document required positional arguments

1 participant