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

Only the last binding is respected in case of multiple bindings with same type #487

Closed
Hritik14 opened this issue Jan 20, 2025 · 1 comment · Fixed by #491
Closed

Only the last binding is respected in case of multiple bindings with same type #487

Hritik14 opened this issue Jan 20, 2025 · 1 comment · Fixed by #491

Comments

@Hritik14
Copy link
Contributor

Consider this:

	my_name := "Alice"
	your_name := "bob"

	ctx := kong.Parse(&cli,
		kong.Vars{
			"version": "0.0.1",
		},
		kong.Bind(my_name, your_name),
	)
func (cmd *BuildCmd) Run(my_name, your_name string, globals *Globals) error {
	fmt.Println("my_name " + my_name + " your_name: " + your_name)
	return nil
}

and run

; ./main build a
my_name bob your_name: bob

This happens because bindings are attached via

kong/callbacks.go

Lines 123 to 125 in 8d238c8

for i := 0; i < t.NumIn(); i++ {
pt := t.In(i)
argf, ok := bindings[pt]

and bindings is a map

type bindings map[reflect.Type]any

@alecthomas
Copy link
Owner

alecthomas commented Jan 20, 2025

This is working as intended. To differentiate between values of the same type you'll need to create a new type:

type MyName string
type YourName string

kong.Bind(FirstName("Alice"), YourName("Bob"))

@alecthomas alecthomas closed this as not planned Won't fix, can't repro, duplicate, stale Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants