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

The default ShellCompDirective can be customized for a command and its subcommands #2238

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

albers
Copy link

@albers albers commented Feb 18, 2025

Closes #2209, #2221

#2221 proposed a solution where the custom DefaultShellCompDirective only applied to a given command.

In #2221 (comment), alternative approaches were discussed.
We agreed on a recursive solution, where a change applies to a command and its subcommands.

To ease review, I open a new PR for this approach.

Comment on lines +118 to +120
// DefaultShellCompDirective sets the ShellCompDirective that is returned
// if no special directive can be determined
DefaultShellCompDirective *ShellCompDirective
Copy link
Contributor

@ccoVeille ccoVeille Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit annoyed by something here

We have an exported field with a pointer.

I remember the discussion that occurred in previous PR about that.

But here, the value the user may expect to be able to pass this field when creating an instance of the struct.

But there is a problem, the existing values they may want to pass are constants (with a iota btw)

But then... You cannot pass a reference to a constant.

I mean this cannot be written

_ = cobra.Command{
	DefaultShellCompDirective: &cobra.ShellCompDirectiveNoFileComp
}

So something else need to be found. i think

Either removing the pointer (and use something else like another constant equal to -1), using variables and not constants, adding a setter...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Set a default completion function
2 participants