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

Escape single quotes in fish shell completion #879

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func testApp() *App {
app.Flags = []Flag{
StringFlag{
Name: "socket, s",
Usage: "some usage text",
Usage: "some 'usage' text",
Value: "value",
TakesFile: true,
},
Expand Down
10 changes: 8 additions & 2 deletions fish.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ func (a *App) prepareFishCommands(commands []Command, allCommands *[]string, pre
))

if command.Usage != "" {
completion.WriteString(fmt.Sprintf(" -d '%s'", command.Usage))
completion.WriteString(fmt.Sprintf(" -d '%s'",
escapeSingleQuotes(command.Usage)))
}

if !command.HideHelp {
Expand Down Expand Up @@ -144,7 +145,8 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string
}

if flag.GetUsage() != "" {
completion.WriteString(fmt.Sprintf(" -d '%s'", flag.GetUsage()))
completion.WriteString(fmt.Sprintf(" -d '%s'",
escapeSingleQuotes(flag.GetUsage())))
}

completions = append(completions, completion.String())
Expand Down Expand Up @@ -182,3 +184,7 @@ func (a *App) fishSubcommandHelper(allCommands []string) string {
return fishHelper

}

func escapeSingleQuotes(input string) string {
return strings.Replace(input, `'`, `\'`, -1)
}
2 changes: 1 addition & 1 deletion testdata/expected-doc-full.man
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
\fB\-\-flag, \-\-fl, \-f\fP="":

.PP
\fB\-\-socket, \-s\fP="": some usage text (default: value)
\fB\-\-socket, \-s\fP="": some 'usage' text (default: value)


.SH COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-full.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]

**--flag, --fl, -f**="":

**--socket, -s**="": some usage text (default: value)
**--socket, -s**="": some 'usage' text (default: value)


# COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion testdata/expected-doc-no-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]

**--flag, --fl, -f**="":

**--socket, -s**="": some usage text (default: value)
**--socket, -s**="": some 'usage' text (default: value)

2 changes: 1 addition & 1 deletion testdata/expected-fish-full.fish
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function __fish_greet_no_subcommand --description 'Test if there has been any su
return 0
end

complete -c greet -n '__fish_greet_no_subcommand' -l socket -s s -r -d 'some usage text'
complete -c greet -n '__fish_greet_no_subcommand' -l socket -s s -r -d 'some \'usage\' text'
complete -c greet -n '__fish_greet_no_subcommand' -f -l flag -s fl -s f -r
complete -c greet -n '__fish_greet_no_subcommand' -f -l another-flag -s b -d 'another usage text'
complete -c greet -n '__fish_greet_no_subcommand' -f -l help -s h -d 'show help'
Expand Down