Skip to content

Option "mapFallbackValue" ignored when inherited to subcommand #2035

Closed

Description

@zman0900

With an @option defined like this:

@Command(
    name = "main"
    subcommands = {
        SubCmd.class,
        CommandLine.HelpCommand.class
    }
)
public class Main {
    @Option(
            names = "-D",
            paramLabel = "<key=value>",
            mapFallbackValue = Option.NULL_VALUE,
            scope = ScopeType.INHERIT
    )
    private final Map<String, String> javaOpts = new HashMap<>();
}

@Command(name = "sub")
public class SubCmd {
    @ParentCommand
    private Main parent;
}

Running with args like ["sub", "-Dxyz"] results in error message:

Value for option option '-D' (<key=value>) should be in KEY=VALUE format but was xyz

This seems like it might be because the ArgSpec Builder copy constructor doesn't copy the "mapFallbackValue" field in picocli 4.7.3: https://github.com/remkop/picocli/blob/v4.7.3/src/main/java/picocli/CommandLine.java#L9496

Activity

  1. remkop commented on Jun 1, 2023

    @remkop
    Owner

    Thank you for raising this, and thank you for the analysis!
    It’s very plausible that that’s the cause.

    Will you be able to provide a pull request for this?

  2. added a commit that references this issue on Jun 1, 2023
    3d5cf22
  3. zman0900 commented on Jun 1, 2023

    @zman0900
    Author

    PR #2036 opened

  4. added this to the 4.7.4 milestone on Jun 1, 2023
  5. added 2 commits that reference this issue on Jun 2, 2023
    5984589
    0bebcc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions