Memoize flag alias resolution by context
This commit is contained in:
@@ -295,3 +295,21 @@ func capturedSpelling(token string) capturedFlagSpelling {
|
||||
issues := []error(nil)
|
||||
return captureFlagSpelling("test", token, &issues)
|
||||
}
|
||||
|
||||
func TestFlagAliasSharedSuffixAndUnavailableDestination(t *testing.T) {
|
||||
app, err := New(Identity{Name: "Example"}, flagAliasCommand("active", stringFlag("color", "")), flagAliasCommand("inactive"),
|
||||
FlagAlias("--first", "--common"), FlagAlias("--second", "--common"), FlagAlias("--common", "--color"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, name := range []string{"first", "second", "common"} {
|
||||
key := flagSpellingKey(capturedFlagSpelling{name: name})
|
||||
active := app.flagAliases[commandpath.Path{"active"}.Key()].bySpelling
|
||||
if alias, ok := active[key]; !ok || alias.target.token() != "--color" {
|
||||
t.Fatalf("active %s = %#v", name, alias)
|
||||
}
|
||||
if _, ok := app.flagAliases[commandpath.Path{"inactive"}.Key()].bySpelling[key]; ok {
|
||||
t.Fatalf("inactive %s was installed", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user