fix: add an xorprefix:"..." option for prefixing xor/and groups

Fixes #343
This commit is contained in:
Alec Thomas
2024-12-29 17:53:41 +09:00
parent cacaace969
commit 47b090f2f4
4 changed files with 31 additions and 1 deletions
+20
View File
@@ -2475,3 +2475,23 @@ func TestCustomTypeNoEllipsis(t *testing.T) {
help := w.String()
assert.NotContains(t, help, "...")
}
func TestPrefixXorIssue343(t *testing.T) {
type DBConfig struct {
Password string `help:"Password" xor:"password" optional:""`
PasswordFile string `help:"File which content will be used for a password" xor:"password" optional:""`
PasswordCommand string `help:"Command to run to retrieve password" xor:"password" optional:""`
}
type SourceTargetConfig struct {
Source DBConfig `help:"Database config of source to be copied from" prefix:"source-" xorprefix:"source-" embed:""`
Target DBConfig `help:"Database config of source to be copied from" prefix:"target-" xorprefix:"target-" embed:""`
}
cli := SourceTargetConfig{}
kctx := mustNew(t, &cli)
_, err := kctx.Parse([]string{"--source-password=foo", "--target-password=bar"})
assert.NoError(t, err)
_, err = kctx.Parse([]string{"--source-password-file=foo", "--source-password=bar"})
assert.Error(t, err)
}