Skip to content
Discussion options

You must be logged in to vote

There's no built-in flag for it. Matching is exact (HasName is slices.Contains(cmd.Names(), name)), but v3 has a hook in exactly the right place: SuggestCommandFunc.

In command_run.go, before looking up the subcommand, the command does this:

name := cmd.parsedArgs.First()
if cmd.SuggestCommandFunc != nil && name != "--" {
    name = cmd.SuggestCommandFunc(cmd.Commands, name)
}
subCmd = cmd.Command(name)

So whatever your function returns is the name used for the lookup. Map the typed name to the real one, ignoring case:

import (
    "context"
    "os"
    "strings"

    "github.com/urfave/cli/v3"
)

func caseInsensitiveCommand(commands []*cli.Command, provided string) string {
    for _, c :=

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@stevewi-niteflyte
Comment options

Answer selected by stevewi-niteflyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants