-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
cli/command/container: unify completion funcs for create and run #5581
base: master
Are you sure you want to change the base?
Conversation
Define completion funcs for create and run together with where the flags are defined. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5581 +/- ##
==========================================
- Coverage 59.60% 59.58% -0.02%
==========================================
Files 345 345
Lines 29103 29093 -10
==========================================
- Hits 17346 17336 -10
Misses 10788 10788
Partials 969 969 |
@thaJeztah My first attempt in #5580 was also to place the completions here, but I was not sure whether this was really approprtiate. The completions add a lot of code that does not contribute to the main purprose of the program. On the other hand, putting the completion logic next to the flag definitions will give you a clear view of the existing completions, forcing authors to think about completion when they work on flags. It probably burns down to how much the developers value the completion code. |
Yes, that was a bit my train of thought, as I think they should go together: when adding a flag, it should come with completion (and vice versa; when removing the flag, the completion can be removed). Putting them together could reduce risks of things like removing a flag (but completion to be left behind), and may be good as a template for others ("oh, adding a flag should also have completion!").
I think it's important for sure! And, fun fact is that whenever "what's important for a good CLI" is brought up in interviews I've had (and know others had), one of the first things that come up is "good completion". From that perspective, I hope that the Cobra completion will help bring implementing proper completion more within reach of "the average engineer working on the CLI code", as now they have no "real" excuse not to add them (being able to write it in Go), plus when doing so having it available for more shells than just Bash.
I think the Cobra completion is more testable; at least, it's possible to have unit-tests for them that can be written in Go (so also would show up in test-coverage). We should probably look at more extensive tests beyond just unit-tests, but I'm already happy with some of the tests covering the basics (it's at least more coverage than we had with the ones in Now, there's things I don't like in the current implementation we have with Cobra;
|
I agree with you regarding the role of completions.
Kubectl has a utility function for that, see here |
run
andcreate
#5580Define completion funcs for create and run together with where the flags are defined.
- A picture of a cute animal (not mandatory but encouraged)