diff --git a/docs_test.go b/docs_test.go index 177eb19491..07997b6d04 100644 --- a/docs_test.go +++ b/docs_test.go @@ -11,7 +11,7 @@ func testApp() *App { app.Flags = []Flag{ StringFlag{ Name: "socket, s", - Usage: "some usage text", + Usage: "some 'usage' text", Value: "value", }, StringFlag{Name: "flag, fl, f"}, diff --git a/fish.go b/fish.go index 0f51065ced..3304d1ac8c 100644 --- a/fish.go +++ b/fish.go @@ -82,7 +82,8 @@ func (a *App) prepareFishCommands( )) if command.Usage != "" { - completion.WriteString(fmt.Sprintf(" -d '%s'", command.Usage)) + completion.WriteString(fmt.Sprintf(" -d '%s'", + escapeSingleQuotes(command.Usage))) } if !command.HideHelp { @@ -149,7 +150,8 @@ func (a *App) prepareFishFlags( } 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()) @@ -169,3 +171,7 @@ func (a *App) fishSubcommandHelper(allCommands []string) string { return fishHelper } + +func escapeSingleQuotes(input string) string { + return strings.Replace(input, `'`, `\'`, -1) +} diff --git a/testdata/expected-doc-full.man b/testdata/expected-doc-full.man index a2d0e6dbac..e7268f09a0 100644 --- a/testdata/expected-doc-full.man +++ b/testdata/expected-doc-full.man @@ -1,5 +1,5 @@ .nh -.TH greet(8) +.TH greet(8) .SH Harrison @@ -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 @@ -77,4 +77,4 @@ another usage test .PP retrieve generic information -.SH some\-command \ No newline at end of file +.SH some\-command diff --git a/testdata/expected-doc-full.md b/testdata/expected-doc-full.md index 8fb9f589d5..23d7c23745 100644 --- a/testdata/expected-doc-full.md +++ b/testdata/expected-doc-full.md @@ -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 diff --git a/testdata/expected-doc-no-commands.md b/testdata/expected-doc-no-commands.md index dba7bb067e..18d8e357e8 100644 --- a/testdata/expected-doc-no-commands.md +++ b/testdata/expected-doc-no-commands.md @@ -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) diff --git a/testdata/expected-fish-full.fish b/testdata/expected-fish-full.fish index 3538c199b0..116b3b73de 100644 --- a/testdata/expected-fish-full.fish +++ b/testdata/expected-fish-full.fish @@ -9,7 +9,7 @@ function __fish_greet_no_subcommand --description 'Test if there has been any su return 0 end -complete -c greet -f -n '__fish_greet_no_subcommand' -l socket -s s -r -d 'some usage text' +complete -c greet -f -n '__fish_greet_no_subcommand' -l socket -s s -r -d 'some \'usage\' text' complete -c greet -f -n '__fish_greet_no_subcommand' -l flag -s fl -s f -r complete -c greet -f -n '__fish_greet_no_subcommand' -l another-flag -s b -d 'another usage text' complete -c greet -f -n '__fish_greet_no_subcommand' -l help -s h -d 'show help'