Skip to content

Argument groups: default value is disregarded #746

@deining

Description

@deining

I'm running the code below (assertions enabled):

package test;

import picocli.CommandLine;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

public class ArgGroupsTest {

    public static void main(String[] args) {
        CommandLine cmd = new CommandLine(new TestCommand());
        cmd.execute();
    }

    @Command(name = "ArgGroupsTest")
    static class TestCommand implements Runnable {

        @ArgGroup( exclusive = false)
        DataSource datasource;

        static class DataSource {
            @Option(names = "-x", arity = "0..1", defaultValue = "999", fallbackValue = "-88" )
            static int x;
        }

        @Override
        public void run() {
            assert TestCommand.DataSource.x== 999;
            System.out.printf("x = %s%n", TestCommand.DataSource.x);
        }
    }
}

Since x = 0, I'm getting:

Exception in thread "main" java.lang.AssertionError
	at test.ArgGroupsTest$TestCommand.run(ArgGroupsTest.java:28)
        ...

Is this the intended behaviour?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions