Skip to content

Commit

Permalink
Move suggestion-related code to suggestions.go
Browse files Browse the repository at this point in the history
Supports #1586
  • Loading branch information
meatballhat committed Dec 18, 2022
1 parent 9e40e8e commit c4074ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
18 changes: 2 additions & 16 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@ import (
"strings"
)

const suggestDidYouMeanTemplate = "Did you mean %q?"

var (
changeLogURL = "https://github.com/urfave/cli/blob/main/docs/CHANGELOG.md"
appActionDeprecationURL = fmt.Sprintf("%s#deprecated-cli-app-action-signature", changeLogURL)
contactSysadmin = "This is an error in the application. Please contact the distributor of this application if this is not you."
ignoreFlagPrefix = "test." // this is to ignore test flags when adding flags from other packages

SuggestFlag SuggestFlagFunc = suggestFlag
SuggestCommand SuggestCommandFunc = suggestCommand
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
)
// ignoreFlagPrefix is to ignore test flags when adding flags from other packages
const ignoreFlagPrefix = "test."

// App is the main structure of a cli application.
type App struct {
Expand Down Expand Up @@ -121,10 +111,6 @@ type App struct {
rootCommand *Command
}

type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string

type SuggestCommandFunc func(commands []*Command, provided string) string

// Setup runs initialization code to ensure all data structures are ready for
// `Run` or inspection prior to `Run`. It is internally called by `Run`, but
// will return early if setup has already happened.
Expand Down
12 changes: 12 additions & 0 deletions suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ import (
"github.com/xrash/smetrics"
)

const suggestDidYouMeanTemplate = "Did you mean %q?"

var (
SuggestFlag SuggestFlagFunc = suggestFlag
SuggestCommand SuggestCommandFunc = suggestCommand
SuggestDidYouMeanTemplate string = suggestDidYouMeanTemplate
)

type SuggestFlagFunc func(flags []Flag, provided string, hideHelp bool) string

type SuggestCommandFunc func(commands []*Command, provided string) string

func jaroWinkler(a, b string) float64 {
// magic values are from https://github.com/xrash/smetrics/blob/039620a656736e6ad994090895784a7af15e0b80/jaro-winkler.go#L8
const (
Expand Down

0 comments on commit c4074ac

Please sign in to comment.