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

Slice option, required and ini file - fails even if required option is specified in ini file #323

Closed
raghur opened this issue Dec 5, 2019 · 1 comment

Comments

@raghur
Copy link

raghur commented Dec 5, 2019

define a slice option as required
read ini file containing said option with a value
Do not specify the option on the cli.

Fails with - 'required option x not specified'
Secondary - if option is specified on CLI, it replaces the option in the ini file (instead of appending)
parseAsDefault does not seem to matter.

Updated 06 dec 2019 - edited to reflect that replacing option is the correct behavior

@raghur
Copy link
Author

raghur commented Dec 5, 2019


func TestIniRequiredSlice_ShouldNotNeedToBeSpecifiedOnCli(t *testing.T) {
	type options struct {
		Items []string `long:"item" required:"true"`
	}
	var opts options
	ini := `
[Application Options]
item=abc`
	args := []string{}

	parser := NewParser(&opts, Default)
	inip := NewIniParser(parser)

	inip.Parse(strings.NewReader(ini))
	inip.ParseAsDefaults = false
	_, err := parser.ParseArgs(args)
	if err != nil {
		t.Fatalf("Unexpected failure: %v", err)
	}

}

raghur added a commit to raghur/go-flags that referenced this issue Dec 6, 2019
raghur added a commit to raghur/go-flags that referenced this issue Dec 6, 2019
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

1 participant