-
Notifications
You must be signed in to change notification settings - Fork 2.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
The default ShellCompDirective can be customized for a command and its subcommands #2238
Open
albers
wants to merge
2
commits into
spf13:main
Choose a base branch
from
albers:default-shellcompdirective-recursive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
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...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent point @ccoVeille . And I agree that users will try to use the field directly from the structure. That’s why we don’t usually have setters.
@albers I assume you foresaw that and that’s why you created the setter.
I had not thought about it before, but reading the comment from @ccoVeille , I think that instead of using a pointer we could use the
shellCompDirectiveMaxValue
to indicate the value has not been setWhat do you guys think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh, my suggestion doesn’t make sense because it’s the compiler that sets the value of
DefaultShellCompDirective
to 0 for every command. That’s why the pointer works because the compiler sets it to nil.I need to think about this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to support the use case of a child command resetting the
DefaultShellCompDirective
toShellCompDirectiveDefault
while its parent has a customDefaultShellCompDirective
(see test), we need a way to initialize the value ofDefaultShellCompDirective
to a new default value likeShellCompDirectiveUndefined
or a pointer, while still preserving backwards compatibility.My first approch may feel a bit clumsy, but it definitely fulfills the requirements. You can create the command with either
or
We could improve (?) this approach by making
DefaultShellCompDirective
private and introduce a getter so that we have a symmetric access pattern that does not tempt users to directly setDefaultShellCompDirective
to the constant.The only alternative I see is to create a factory method
newCommand
that takes care of initializingDefaultShellCompDirective
, something likeBut this is definitely not an improvement to the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albers your examples have convinced me that this is good enough. Let’s go with it as is, if you can just fix the docs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get where we are going.
If the argument was "yes, the setter approach was better", I would have say yes. But, here it sounds like something strange to me.
Expecting people to deal with pointer on constants. It looks a bit odd.
here are some suggestions:
I'm unsure this one makes sense, but maybe it would help you guys to find something better around a boolean.
people could use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach does not fulfill the requirements because it is not recursive.
The user would have to define the property on each subcommand that should inherit the setting.
The
ShellCompDirectives
are constants for a good reason.The should not be modifyable.
Well, we could add a
ToPointer
function for that purpose, WDYT @marckhouzam ?