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

rpk: Unknown flag error when command is misspelled #4377

Open
travisdowns opened this issue Apr 21, 2022 · 3 comments
Open

rpk: Unknown flag error when command is misspelled #4377

travisdowns opened this issue Apr 21, 2022 · 3 comments
Assignees
Labels
area/rpk kind/bug Something isn't working

Comments

@travisdowns
Copy link
Member

travisdowns commented Apr 21, 2022

Version & Environment

Redpanda version: 21.11.10

What went wrong?

Consider the following command and error output:

rpk topic add-paritions t0 --num 1000
Error: unknown flag: --num

What should have happened instead?

The error should be "Unknown command add-paritions" (it is misspelled) rather than a complaint about the flag, which is correct for the (correctly spelled) command.

How to reproduce the issue?

  1. As above.

JIRA Link: CORE-890

@travisdowns travisdowns added kind/bug Something isn't working area/rpk labels Apr 21, 2022
@daisukebe
Copy link
Contributor

daisukebe commented Apr 25, 2022

It seems to be emitted by cobra, https://github.com/spf13/cobra/blob/v1.1.3/command.go#L942-L944, and apparently the latest cobra 1.4.0 works in the same way.

Within rpk, we can interrupt with a way like below, but I'm unsure whether this is fine.

src/go/rpk/pkg/cli/cmd/topic.go

	if _, _, err := command.Find(os.Args[2:]); err != nil {
		log.Info(err)
		os.Exit(1)
	}

	return command
}

Example output with above:

$ rpk topic add-paritions bar --num 10
unknown command "add-paritions" for "topic"

Did you mean this?
	add-partitions

Related discussion in the cobra community, spf13/cobra#706

@r-vasquez r-vasquez self-assigned this Apr 26, 2022
@r-vasquez
Copy link
Contributor

r-vasquez commented May 16, 2022

Thanks @daisukebe for the context, indeed the problem does not go away with cobra 1.4.0. This is an issue in cobra side:

spf13/cobra#1409

If this is something that we need, we may go with the above approach and interrupt in each command, or another thing that we could do is to add additional info in the flag errors, e.g:

Currently:

$ rpk topic add-paritions t0 --num 1000

Error: unknown flag: --num

<Usage for rpk topic>

We can do something like:

$ rpk topic add-paritions t0 --num 1000

Error: unknown flag: --num
See 'rpk topic --help'

<Usage for rpk topic>

However I think is redundant since we already print the usage, what do you think?

CC: @twmb

@twmb
Copy link
Contributor

twmb commented May 16, 2022

I agree this is more in the guts of cobra. Perhaps long term we can evaluate switching away from cobra (which has a bunch of other challenging nuts&bolts we currently work around / with). For now, I think we can wait for the two cobra issues linked above for now and leave this open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rpk kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants