-
Notifications
You must be signed in to change notification settings - Fork 3
sync upstream #21
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
sync upstream #21
Changes from all commits
ba5108a
73f7846
0846d16
0ed70dc
67171d6
db3ddb5
75790e4
4af7b64
c8289c1
6dec1ae
dcaf42e
3f3b818
51d6751
7da941c
0629892
e2dd29d
117698a
fc81d20
346d408
88b30ab
10d4b48
61968e8
85c12c2
f2878ba
746ef07
ad460ea
2bf318f
66c25c4
78f8f10
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,6 +115,13 @@ type CompletionOptions struct { | |||||||||||||
| DisableDescriptions bool | ||||||||||||||
| // HiddenDefaultCmd makes the default 'completion' command hidden | ||||||||||||||
| HiddenDefaultCmd bool | ||||||||||||||
| // DefaultShellCompDirective sets the ShellCompDirective that is returned | ||||||||||||||
| // if no special directive can be determined | ||||||||||||||
| DefaultShellCompDirective *ShellCompDirective | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| func (receiver *CompletionOptions) SetDefaultShellCompDirective(directive ShellCompDirective) { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Code Quality] Non-idiomatic receiver name
func (o *CompletionOptions) SetDefaultShellCompDirective(directive ShellCompDirective) { |
||||||||||||||
| receiver.DefaultShellCompDirective = &directive | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+123
to
125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The receiver name
Suggested change
|
||||||||||||||
|
|
||||||||||||||
| // Completion is a string that can be used for completions | ||||||||||||||
|
|
@@ -310,7 +317,10 @@ func (c *Command) getCompletions(args []string) (*Command, []Completion, ShellCo | |||||||||||||
| // The last argument, which is not completely typed by the user, | ||||||||||||||
| // should not be part of the list of arguments | ||||||||||||||
| toComplete := args[len(args)-1] | ||||||||||||||
| trimmedArgs := args[:len(args)-1] | ||||||||||||||
| // Copy trimmedArgs to a new slice to avoid mutating the caller's | ||||||||||||||
| // backing array (which may be os.Args) when later appending "--". | ||||||||||||||
| trimmedArgs := make([]string, len(args)-1) | ||||||||||||||
| copy(trimmedArgs, args[:len(args)-1]) | ||||||||||||||
|
|
||||||||||||||
| var finalCmd *Command | ||||||||||||||
| var finalArgs []string | ||||||||||||||
|
|
@@ -375,7 +385,7 @@ func (c *Command) getCompletions(args []string) (*Command, []Completion, ShellCo | |||||||||||||
| // Error while attempting to parse flags | ||||||||||||||
| if flagErr != nil { | ||||||||||||||
| // If error type is flagCompError and we don't want flagCompletion we should ignore the error | ||||||||||||||
| if _, ok := flagErr.(*flagCompError); !(ok && !flagCompletion) { | ||||||||||||||
| if _, ok := flagErr.(*flagCompError); !ok || flagCompletion { | ||||||||||||||
| return finalCmd, []Completion{}, ShellCompDirectiveDefault, flagErr | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
@@ -480,6 +490,14 @@ func (c *Command) getCompletions(args []string) (*Command, []Completion, ShellCo | |||||||||||||
| } | ||||||||||||||
| } else { | ||||||||||||||
| directive = ShellCompDirectiveDefault | ||||||||||||||
| // check current and parent commands for a custom DefaultShellCompDirective | ||||||||||||||
| for cmd := finalCmd; cmd != nil; cmd = cmd.parent { | ||||||||||||||
| if cmd.CompletionOptions.DefaultShellCompDirective != nil { | ||||||||||||||
| directive = *cmd.CompletionOptions.DefaultShellCompDirective | ||||||||||||||
| break | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if flag == nil { | ||||||||||||||
| foundLocalNonPersistentFlag := false | ||||||||||||||
| // If TraverseChildren is true on the root command we don't check for | ||||||||||||||
|
|
@@ -773,7 +791,7 @@ See each sub-command's help for details on how to use the generated script. | |||||||||||||
| // shell completion for it (prog __complete completion '') | ||||||||||||||
| subCmd, cmdArgs, err := c.Find(args) | ||||||||||||||
| if err != nil || subCmd.Name() != compCmdName && | ||||||||||||||
| !(subCmd.Name() == ShellCompRequestCmd && len(cmdArgs) > 1 && cmdArgs[0] == compCmdName) { | ||||||||||||||
| (subCmd.Name() != ShellCompRequestCmd || len(cmdArgs) <= 1 || cmdArgs[0] != compCmdName) { | ||||||||||||||
| // The completion command is not being called or being completed so we remove it. | ||||||||||||||
| c.RemoveCommand(completionCmd) | ||||||||||||||
| return | ||||||||||||||
|
|
@@ -940,6 +958,7 @@ func CompDebug(msg string, printToStdErr bool) { | |||||||||||||
| // Such logs are only printed when the user has set the environment | ||||||||||||||
| // variable BASH_COMP_DEBUG_FILE to the path of some file to be used. | ||||||||||||||
| if path := os.Getenv("BASH_COMP_DEBUG_FILE"); path != "" { | ||||||||||||||
| //nolint:gosec // G703:BASH_COMP_DEBUG_FILE intentionally user-controlled for completion debug logging. | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Security - Low] Wrong gosec rule ID in nolint annotation The comment cites //nolint:gosec // G304: BASH_COMP_DEBUG_FILE is intentionally user-controlled for completion debug logging. |
||||||||||||||
| f, err := os.OpenFile(path, | ||||||||||||||
| os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) | ||||||||||||||
| if err == nil { | ||||||||||||||
|
|
||||||||||||||
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.
[Code Quality] Doc comment doesn't explain pointer semantics or scope
The pointer is needed to distinguish
nil("not set, inherit from parent") from0(ShellCompDirectiveDefault). This non-obvious design should be documented on the field: