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

Combination of required and enum cause other sub-command failure #40

Closed
juliaogris opened this issue Nov 19, 2019 · 4 comments
Closed

Comments

@juliaogris
Copy link
Contributor

For given sample:

package main

import (
	"fmt"

	"github.com/alecthomas/kong"
)

var CLI struct {
	One struct {
		OneArg string `arg:"" required:""`
	} `cmd: ""`
	Two struct {
		TwoArg string `arg:"" enum:"a,b,c" required:""`
	} `cmd: ""`
}

func main() {
	ctx := kong.Parse(&CLI)
	switch cmd := ctx.Command(); cmd {
	case "one <one-arg>", "two <two-arg>":
		fmt.Println("command:", cmd)
	default:
		panic(ctx.Command())
	}
}

I expect the following behaviour:

> go run main.go one X
command: one <one-arg>
> go run main.go two a
command: two <two-arg>

However, I get:

> go run main.go one X          
main: error: <two-arg> must be one of "a","b","c" but got ""
exit status 1
> go run main.go two a
command: two <two-arg>

When I remove the enum tag or replace required with default:"a" in command two, command one behaves as expected.

@alecthomas
Copy link
Owner

Are you on master? I fixed some bugs with this recently.

@juliaogris
Copy link
Contributor Author

juliaogris commented Nov 20, 2019

I am now on master and I still get the same error for go.mod:

module github.com/juliaogris/kongenum

go 1.13

require github.com/alecthomas/kong v0.2.2-0.20191112213115-d2286db01b8f

juliaogris added a commit to juliaogris/kongenum that referenced this issue Nov 20, 2019
Initialise sample code to demonstrate issue
(alecthomas/kong#40).

Expected behaviour:

	> go run main.go one X
	command: one <one-arg>
	> go run main.go two a
	command: two <two-arg>

Actual behaviour:

	> go run main.go one X
	main: error: <two-arg> must be one of "a","b","c" but got ""
	exit status 1
	> go run main.go two a
	command: two <two-arg>
juliaogris added a commit to juliaogris/kongenum that referenced this issue Nov 20, 2019
Initialise sample code to demonstrate issue
(alecthomas/kong#40).

Expected behaviour:

	> go run main.go one X
	command: one <one-arg>
	> go run main.go two a
	command: two <two-arg>

Actual behaviour:

	> go run main.go one X
	main: error: <two-arg> must be one of "a","b","c" but got ""
	exit status 1
	> go run main.go two a
	command: two <two-arg>
@alecthomas
Copy link
Owner

Okay that should be fixed now. Let me know if it's still failing for your use case.

@juliaogris
Copy link
Contributor Author

Confirmed! Thank you very much - great library.

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

No branches or pull requests

2 participants