Kubebuilder: Error `invalid value for project version` appears without let us know what values are available

Created on 17 Dec 2020  路  11Comments  路  Source: kubernetes-sigs/kubebuilder

Unable to use the help to check the plugins versions available for an project version:

 $ kubebuilder init --project-version=v3-alpha --plugins=h
2020/12/17 12:00:07 invalid value for project version (regex used for validation is '[1-9][0-9]*(?:-(?:alpha|beta))?')

When I would expect to see:

$ kubebuilder init --project-version=3
Error: no resolved plugins, please specify plugins with --project-version or/and --plugins flags
Usage:
  kubebuilder init [flags]

Examples:
  # Help for initializing a project with version "2"
  kubebuilder init --project-version="2" -h

  # Help for initializing a project with version "3-alpha"
  kubebuilder init --project-version="3-alpha" -h

Flags:
  -h, --help                     help for init
      --plugins strings          Name and optionally version of the plugin to initialize the project with. Available plugins: ("go.kubebuilder.io/v2", "go.kubebuilder.io/v3")
      --project-version string   project version, possible values: ("2", "3-alpha") (default "3-alpha")

2020/12/17 12:12:19 no resolved plugins, please specify plugins with --project-version or/and --plugins flags

PS.: It shows a bug introduced in the latest changes.
c/c @estroz @Adirio

kinbug triagaccepted

All 11 comments

Project versions do not support the v prefix:

$ kubebuilder init --project-version=3-alpha --plugins=h

Yeah this is a validation error. I don't see what better error kubebuilder could produce if the project version doesn't have the correct format.

/remove-kind bug

Closing this as it should be solved just by removing the invalid v character. Reopen if the error is still present afterwards.

/close

@Adirio: Closing this issue.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Hi @Adirio @estroz,

The point here is that invalid value for project version (regex used for validation is '[1-9][0-9]*(?:-(?:alpha|beta))?') are not helpful for the users at all. put yourself in the user fits, how you would know the possible project version available and what info you should pass with this error mensage?

We should output the help with that. For all CLI errors, we should output the help and not ONLY the error itself. Is not the common behaviour for the CLI? PS.: I believe that it was showing the help before the latest changes.

```
$ kubebuilder init --project-version=3
Error: no resolved plugins, please specify plugins with --project-version or/and --plugins flags
Usage:
kubebuilder init [flags]

Examples:
# Help for initializing a project with version "2"
kubebuilder init --project-version="2" -h

# Help for initializing a project with version "3-alpha"
kubebuilder init --project-version="3-alpha" -h

Flags:
-h, --help help for init
--plugins strings Name and optionally version of the plugin to initialize the project with. Available plugins: ("go.kubebuilder.io/v2", "go.kubebuilder.io/v3")
--project-version string project version, possible values: ("2", "3-alpha") (default "3-alpha")
```

Outputting command help is fine with me, or a list of available project versions.

It is a bug because what is expected for any CLI/tool command is:

  • If an invalid arg or value be used to run the command then, the tool should return error with the help
  • The help should provide the possible options available

I 100% agree that printing the regex is not a very good UX, I will work on showing the available project versions instead of the regex. IMO printing the whole command help should be reserved for those cases where the use intention is not clear. In this case the intention is clearly to provide a valid project version but he failed, so a clear error message that includes available project versions should be clear an concise while printing the whole command help may add noise.

/assign

With #1937, the output to kubebuilder init --project-version=v3-alpha --plugins=h is:

Error: invalid value for project version (regex used for validation is '[1-9][0-9]*(?:-(?:alpha|beta))?')
Usage:
  kubebuilder [flags]

Examples:
The first step is to initialize your project:
    kubebuilder init --project-version=<PROJECT VERSION> --plugins=<PLUGIN KEYS>

<PLUGIN KEYS> is a comma-separated list of plugin keys from the following table
and <PROJECT VERSION> a supported project version for these plugins.

          Plugin keys | Supported project versions
----------------------+----------------------------
 go.kubebuilder.io/v2 |                 2, 3-alpha
 go.kubebuilder.io/v3 |                    3-alpha

For more specific help for the init command of a certain plugins and project version
configuration please run:
    kubebuilder init --help --project-version=<PROJECT VERSION> --plugins=<PLUGIN KEYS>

Default project version: 3-alpha
Default plugin keys: "go.kubebuilder.io/v3"

After the project has been initialized, run
    kubebuilder --help
to obtain further info about available commands.

Flags:
  -h, --help                     help for kubebuilder
      --plugins strings          plugin keys of the plugin to initialize the project with
      --project-version string   project version (default "3-alpha")

2021/01/13 07:39:49 invalid value for project version (regex used for validation is '[1-9][0-9]*(?:-(?:alpha|beta))?')

Should this be enough? Any suggested changes?

Was this page helpful?
0 / 5 - 0 ratings