Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aliases can be duplicated between different sub commands #419

Merged
merged 1 commit into from Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.go
Expand Up @@ -170,6 +170,9 @@ MAIN:
if flag.Short != 0 {
delete(seenFlags, "-"+string(flag.Short))
}
for _, aflag := range flag.Aliases {
delete(seenFlags, "--"+aflag)
}
}

if err := validatePositionalArguments(node); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions kong_test.go
Expand Up @@ -1340,6 +1340,20 @@ func TestDuplicateAliases(t *testing.T) {
assert.EqualError(t, err, "<anonymous struct>.Flag2: duplicate flag --flag")
}

func TestSubCommandAliases(t *testing.T) {
type SubC struct {
Flag1 string `aliases:"flag"`
}

cli1 := struct {
Sub1 SubC `cmd:"sub1"`
Sub2 SubC `cmd:"sub2"`
}{}

_, err := kong.New(&cli1)
assert.NoError(t, err, "dupe aliases shouldn't error if they're in separate sub commands")
}

func TestDuplicateAliasLong(t *testing.T) {
cli2 := struct {
Flag string ``
Expand Down