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
Add TakesFile
to fish shell completion
#857
Merged
AudriusButkevicius
merged 4 commits into
urfave:master
from
saschagrunert:takes-file-fish
Aug 29, 2019
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ func (a *App) prepareFishCommands( | |
|
||
var completion strings.Builder | ||
completion.WriteString(fmt.Sprintf( | ||
"complete -c %s -f -n '%s' -a '%s'", | ||
"complete -r -c %s -n '%s' -a '%s'", | ||
a.Name, | ||
a.fishSubcommandHelper(previousCommands), | ||
strings.Join(command.Names(), " "), | ||
|
@@ -124,13 +124,15 @@ func (a *App) prepareFishFlags( | |
continue | ||
} | ||
|
||
var completion strings.Builder | ||
completion := &strings.Builder{} | ||
completion.WriteString(fmt.Sprintf( | ||
"complete -c %s -f -n '%s'", | ||
"complete -c %s -n '%s'", | ||
a.Name, | ||
a.fishSubcommandHelper(previousCommands), | ||
)) | ||
|
||
fishAddFileFlag(f, completion) | ||
|
||
for idx, opt := range strings.Split(flag.GetName(), ",") { | ||
if idx == 0 { | ||
completion.WriteString(fmt.Sprintf( | ||
|
@@ -158,6 +160,25 @@ func (a *App) prepareFishFlags( | |
return completions | ||
} | ||
|
||
func fishAddFileFlag( | ||
flag Flag, | ||
completion *strings.Builder, | ||
) { | ||
addFileExclusionFlag := true | ||
if f, ok := flag.(GenericFlag); ok && f.TakesFile { | ||
addFileExclusionFlag = false | ||
} | ||
if f, ok := flag.(StringFlag); ok && f.TakesFile { | ||
addFileExclusionFlag = false | ||
} | ||
if f, ok := flag.(StringSliceFlag); ok && f.TakesFile { | ||
addFileExclusionFlag = false | ||
} | ||
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.
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 comma separated type switch does not seem to work, fallthrough does also not work so I had to add dedicated statements for each type. |
||
if addFileExclusionFlag { | ||
completion.WriteString(" -f") | ||
} | ||
} | ||
|
||
func (a *App) fishSubcommandHelper(allCommands []string) string { | ||
fishHelper := fmt.Sprintf("__fish_%s_no_subcommand", a.Name) | ||
if len(allCommands) > 0 { | ||
|
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.
Is gofmt happy with 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.
Yes :)
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.
Looks fairly non-standard. There aren't that many arguments that it would require this ackward breaking. Is this standard in this project or are you bringing your own twist to this?
Reason I am asking is that format consistency is important in a project with multiple collaborators
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.
It is standard in this file, but since I'm the main author I would say it is just my own twist. I will align with the project standard (single line) and change the other functions, too.