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

Wrong flag generated with anonymous embedded struct #55

Description

@ogerardin

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions