cobra icon indicating copy to clipboard operation
cobra copied to clipboard

feat(completion): add option to create default command alone

Open scop opened this issue 4 years ago • 9 comments
trafficstars

The current implementation of the default completion (and help) commands makes them available only when there are some other commands defined. This rules them out for apps that have no other subcommands, either by design anew, or for historical behavior, even though they would benefit from completions both in the first place, and the convenience of having the default generated.

This adds a new completion option for having the default init happen in those cases. Not that clean in the first place and the variable name is a mouthful, but the functionality would be great to have.

Untested, mainly for discussion purposes, but in absence of something better, I'd be fine with something like this.

scop avatar May 06 '21 13:05 scop

Thanks for the PR @scop. I now realize that there is value in a completion command even for tools that don't have subcommands. It would allow flags to be completed, as well as allowing for custom completions of arguments and flag values.

However I am not sure of the right approach for the best user experience. Allowing the creation of the completion command changes the help text because sub-commands now exist. There may be other impacts to the tool when creating a first sub-commands, I'm not sure.

And completion itself isn't as smooth as usual because when doing completion of arguments, the completion and help commands will also be suggested, which are not "arguments", so may cause confusion.

But I agree that it probably has more value to have the completion command than those small disadvantages. And with your proposal, it is up to the developper to decide to enable the completion command, so they can evaluate the impacts.

I just wanted to continue your discussion and see if others had suggestions about this.

marckhouzam avatar May 10 '21 15:05 marckhouzam

This PR is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Jul 10 '21 00:07 github-actions[bot]

Still valid

marckhouzam avatar Jul 10 '21 01:07 marckhouzam

Sorry about the delay in following up. I agree with the concerns flagged by @marckhouzam, and made an alternative implementation in #1450 that doesn't have those problems. It's not that nice that the completion command is completely hidden, but better than the alternatives I believe.

scop avatar Jul 10 '21 09:07 scop

A middle ground could be worth considering as well: let the default completion generate the help section in the usage output, but avoid them being offered as completions. Guess that would be somewhat more code though.

scop avatar Jul 10 '21 09:07 scop

We could also introduce a command like ForceCreationDespiteLoneCommand along the lines of DisableDefaultCmd. For me it was counter-intuitive that the completion command wasn't available and that not being configurable using a completion option.

fabstu avatar Jul 16 '21 16:07 fabstu

I believe this has been replaced by #1450

marckhouzam avatar Sep 24 '21 23:09 marckhouzam

As mentioned in a couple of comments here and in #1450, #1450 is an alternative implementation. It will replace this one if the approach in it is chosen, and vice versa, depends on the decision which one is replaced by which.

scop avatar Sep 25 '21 06:09 scop