Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.Args added as flags to command #2104

Open
kate-osborn opened this issue Jan 30, 2024 · 0 comments
Open

os.Args added as flags to command #2104

kate-osborn opened this issue Jan 30, 2024 · 0 comments

Comments

@kate-osborn
Copy link

Problem

I have unit tests that cover creating cobra commands, and when I run them using Ginkgo, I get an error about an unknown flag that I never explicitly added to the command:

  [FAILED] Unexpected error:
      <*errors.errorString | 0xc000191db0>: 
      unknown flag: --test.timeout
      {
          s: "unknown flag: --test.timeout",
      }
  occurred

The --test.timeout flag is one of the arguments that Ginkgo passes to the compiled Ginkgo test binary and has nothing to do with the command under test.

This only happens with commands that have no arguments and seems to be related to this line of code:

cobra/command.go

Line 1080 in bcfcff7

// Workaround FAIL with "go test -v" or "cobra.test -test.v", see #155

Expected behavior

Cobra does not add the os.Args to the command's args when they are testing-related.

Steps to reproduce

To reproduce, please see my gist where I have recreated the problem with minimal code: https://gist.github.com/kate-osborn/f21aec497bf7ccb81d73ffcfc5e963b0.

The gist includes instructions on how to run the tests.

Environment

cobra version: v1.8.0
ginkgo version: v2.15.0

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

No branches or pull requests

1 participant