Skip to content

No way to turn off - -> _ conversion for flag args #126

@mieubrisse

Description

@mieubrisse

I defined an argument to parse like so:

    private static final String GOV_CONSTANTS_FILEPATH_ARG = "gov-constants";

        ArgumentParser parser = ArgumentParsers.newFor("Financial Predictor").build()
                .defaultHelp(true)
                .description("A financial modelling CLI");
        parser.addArgument("--" + GOV_CONSTANTS_FILEPATH_ARG)
                .required(true)
                .help("YAML file of gov constants per year");

but I was very confused why the following was showing a null value:

        String govConstantsFilepath = parsedArgs.getString(GOV_CONSTANTS_FILEPATH_ARG);
        LOG.debug("Gov constants filepath: {}", govConstantsFilepath);

When I printed the Namespace object, turns out argparse4j is changing the case of the output:

Namespace: Namespace(gov_constants=gov-constants.yml)

This was very unexpected, and only after some digging did I find the noDestConversionForPositionalArgs flag on the builder. However, even with this flag to true, my --gov-constants flag arg gets registered in the Namespace as gov_constants.

It seems likely most people would reuse a single constant for both defining the argument and retrieving the arg from the namespace, so I'm curious what the rationale is for doing the conversion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions