Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

Wrong flag generated with anonymous embedded struct #55

Open
ogerardin opened this issue Apr 11, 2019 · 0 comments
Open

Wrong flag generated with anonymous embedded struct #55

ogerardin opened this issue Apr 11, 2019 · 0 comments
Labels

Comments

@ogerardin
Copy link

The doc says that you can use anonymous sub-structures, and the example implies that when the flag name is generated, the sub-structure is "squashed" (see --db.ip in the example).

I have a case that demonstrates a bug in the generation of the flag name, when an anonymous sub-structure follows a named sub-structure.

This configuration:

type EmbeddedConfig struct {
	P2 int `description:"p2"`
}

type Config struct{
	P1 int `description:"p1"`
	EmbeddedConfig
}

generates the following flags:

Flags:
    --p1    p1                                 (default "0")
    --p1.p2 p2                                 (default "0")

The second flag should be --p2, not --p1.p2

If you swap the members of Config (P1 after the anonymous EmbeddedConfig), the flags are generated correctly
Attached is a source file that shows this behaviour.

flaeg_test.go.zip

@ldez ldez added the bug label Apr 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants