Skip to content

pointer-embedded fields are not supported #240

@purpleidea

Description

@purpleidea

I was doing some lovely refactoring and I was able to take my main tool's config struct, separate it out, decorate it with the arg struct tags, and then embed it both in my main struct and also in a new struct which also included some fields for sub commands.

I then got the following error:

RunArgs.Config: *lib.Config fields are not supported

The struct looks approximately like this:

type RunArgs struct {

	*lib.Config // embedded config XXX: this line breaks things!

	RunEmpty *cliUtil.EmptyArgs `arg:"subcommand:empty" help:"run empty payload"`
	RunLang  *cliUtil.LangArgs  `arg:"subcommand:lang" help:"run lang (mcl) payload"`
}

In the lib package:

type Config struct {
	// Program is the name of this program, usually set at compile time.
	Program string

	// Version is the version of this program, usually set at compile time.
	Version string

	Hostname *string `arg:"--hostname" help:"hostname to use"`

	// ...
}

It seems we don't support the embedded struct? Either this is a "feature we need to add" or there's some gotcha I don't know about. In either case, I'd appreciate your feedback, and would appreciate a patch even more!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions