CLI: remaining gaps after the PROJECT read fixes (#5845, #5942, #6030)
Summary
The recent fixes stopped version, help and completion from failing on a
bad PROJECT file. A few cases are still wrong on master (506e94a). One of
them deletes user files.
1. alpha generate --plugins deletes the project on an unknown layout
The layout names a plugin the CLI does not have. --plugins does not make
that project usable, but alpha generate still wipes the directory before it
fails:
$ cat PROJECT
version: "3"
layout:
- gone.example.com/v1
$ ls
PROJECT notes.txt
$ kubebuilder alpha generate --plugins go.kubebuilder.io/v4
ERROR CLI run failed error=error executing command: no plugin could be resolved with key "gone.example.com/v1"
$ echo $?
1
$ ls -A
$Expected: it fails and leaves every file in place.
2. A bad --plugins value on a command group is ignored
$ kubebuilder create --plugins //
Scaffold a Kubernetes API or webhook.
...
$ echo $?
0Expected: the bad value is reported and the exit code is 1, as it is for
kubebuilder create api --plugins //. Same for kubebuilder alpha --plugins //.
3. TAB no longer offers the flags of the plugins in layout
With a layout that names deploy-image.go.kubebuilder.io/v1-alpha:
$ kubebuilder create api --i<TAB>Expected: --image, --image-container-command, --image-container-port.
Now nothing is offered.
4. Commands added by other tools (WithExtraCommands, WithExtraAlphaCommands)
For projects that build their own CLI on pkg/cli, such as Operator-SDK:
- On a broken
PROJECTfile, the command is refused, but the tool'sArgscheck has already run. It should not run. tool docs --plugins --helpshows help, but runs the tool'sArgscheck first.- With no
PROJECTfile, aRun,PreRunorPersistentPreRunthe tool sets after handing the command over does not run.
5. The first-word rule uses the command name, not the word typed
A tool command named docs with the alias version:
tool docsruns on a brokenPROJECTfile. It should be refused.- A command named
docstyped astool versionis refused. It should run, becauseversionis the first word.
6. A second run can scaffold with the wrong plugin chain
A tool builds the command tree for one plugin chain, then runs create api in
a project whose layout names another. The first run fails, as it should. A
second run on the same CLI scaffolds with the chain the tree was built from.
It should fail again.
How this was found
Black-box tests that build master and run the CLI, plus small programs that
use pkg/cli as a library.
Source: kubernetes-sigs/kubebuilder