Skip to content

How to configure enum case-insensitivity? #556

@helpermethod

Description

@helpermethod

I have a CLI root command like the following

@Command(
    name = "mock-cli",
    mixinStandardHelpOptions = true,
    subcommands = {
        Create.class,
        List.class,
        Show.class
    }
)
public class Cli implements Runnable {
    @Override
    public void run() {
        new CommandLine(this).usage(System.out);
    }

    public static void main(String... args) {
        CommandLine.run(new Cli(), System.out, args);
    }
}

And a subcommand like this

@Command(name = "create", description = "creates a configuration or mapping")
public class Create implements Runnable {
    @Command
    public void config(@Parameters String name,
                       @Option(names = {"-t", "--mime-type"}) java.util.List<MimeType> mimeTypes,
                       @Option(names = {"-p", "--proxy"}) String proxy) {
        try (Writer writer = Files.newBufferedWriter(Paths.get("service/conf/mock-services", name + ".conf"))) {
            compile("create/config")
                .render(Maps.of("name", name,
                    "upperName", name.toUpperCase(),
                    "mimeTypes", mimeTypes,
                    "proxy", proxy),
                    writer);
        } catch (IOException e) {
            // TODO
        }
    }

    @Override
    public void run() {
        new CommandLine(this).usage(out);
    }
}

Now, this works fine so far but I wonder how to configure enum case-insensitivity on the Commandline object? And where? One the rootcommand`?

Metadata

Metadata

Assignees

No one assigned

    Labels

    theme: parserAn issue or change related to the parser

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions