Also make the did-you-mean template pluggable
This commit is contained in:
parent
68bd4903fd
commit
5bb9f453dc
9
app.go
9
app.go
@ -11,7 +11,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const didYouMeanTemplate = "Did you mean '%s'?"
|
||||
const suggestDidYouMeanTemplate = "Did you mean %q?"
|
||||
|
||||
var (
|
||||
changeLogURL = "https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md"
|
||||
@ -21,8 +21,9 @@ var (
|
||||
fmt.Sprintf("Must be `func(*Context`)` or `func(*Context) error). %s", contactSysadmin)+
|
||||
fmt.Sprintf("See %s", appActionDeprecationURL), 2)
|
||||
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
|
||||
)
|
||||
|
||||
// App is the main structure of a cli application. It is recommended that
|
||||
@ -361,7 +362,7 @@ func (a *App) suggestFlagFromError(err error, command string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf(didYouMeanTemplate+"\n\n", suggestion), nil
|
||||
return fmt.Sprintf(SuggestDidYouMeanTemplate+"\n\n", suggestion), nil
|
||||
}
|
||||
|
||||
// RunAndExitOnError calls .Run() and exits non-zero if an error was returned
|
||||
|
@ -27,8 +27,9 @@ application:
|
||||
VARIABLES
|
||||
|
||||
var (
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
|
||||
)
|
||||
var AppHelpTemplate = `NAME:
|
||||
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
|
||||
|
@ -47,5 +47,5 @@ func suggestCommand(commands []*Command, provided string) (suggestion string) {
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Sprintf(didYouMeanTemplate, suggestion)
|
||||
return fmt.Sprintf(SuggestDidYouMeanTemplate, suggestion)
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ func TestSuggestFlagFromError(t *testing.T) {
|
||||
)
|
||||
|
||||
// Then
|
||||
expect(t, res, fmt.Sprintf(didYouMeanTemplate+"\n\n", testCase.expected))
|
||||
expect(t, res, fmt.Sprintf(SuggestDidYouMeanTemplate+"\n\n", testCase.expected))
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,7 +116,7 @@ func TestSuggestCommand(t *testing.T) {
|
||||
res := suggestCommand(app.Commands, testCase.provided)
|
||||
|
||||
// Then
|
||||
expect(t, res, fmt.Sprintf(didYouMeanTemplate, testCase.expected))
|
||||
expect(t, res, fmt.Sprintf(SuggestDidYouMeanTemplate, testCase.expected))
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,7 +140,7 @@ func ExampleApp_Suggest() {
|
||||
// Output:
|
||||
// Incorrect Usage. flag provided but not defined: -nema
|
||||
//
|
||||
// Did you mean '--name'?
|
||||
// Did you mean "--name"?
|
||||
//
|
||||
// (this space intentionally left blank)
|
||||
}
|
||||
@ -181,7 +181,7 @@ func ExampleApp_Suggest_command() {
|
||||
// Output:
|
||||
// Incorrect Usage: flag provided but not defined: -sliming
|
||||
//
|
||||
// Did you mean '--smiling'?
|
||||
// Did you mean "--smiling"?
|
||||
//
|
||||
// (this space intentionally left blank)
|
||||
}
|
||||
|
5
testdata/godoc-v2.x.txt
vendored
5
testdata/godoc-v2.x.txt
vendored
@ -27,8 +27,9 @@ application:
|
||||
VARIABLES
|
||||
|
||||
var (
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestFlag SuggestFlagFunc = suggestFlag
|
||||
SuggestCommand SuggestCommandFunc = suggestCommand
|
||||
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
|
||||
)
|
||||
var AppHelpTemplate = `NAME:
|
||||
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user