-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fallbackValue
NULL_VALUE does not work for Collection options (was: How do I get picocli to parse "--item --item foo"
as [null, "foo"]
:List<String>
)
#1993
Comments
Instead of The fallback value is what is used when the option is specified without parameter. The default value is what is applied when the option is not specified on the command line at all. |
Looking at the answer on SO, https://stackoverflow.com/a/74275000/1047788, it looks like I tried fallbackValue as well and it did not work for me either, so then I resorted to the workaround. I'll try this again to see if I can still confirm what I observed then. Thanks for your suggestion! |
@remkop As I worried, import org.junit.jupiter.api.Test;
import org.powermock.reflect.Whitebox;
import picocli.CommandLine;
import java.util.List;
import java.util.concurrent.Callable;
import static com.google.common.truth.Truth.assertThat;
@CommandLine.Command(
name = "sender",
mixinStandardHelpOptions = true,
version = "1.0.0",
description = "Opens AMQP connections"
)
public class MyMain implements Callable<Integer> {
// e.g. `--item --item "someString"`
@CommandLine.Option(names = {"--item"}, arity = "0..1", fallbackValue = CommandLine.Option.NULL_VALUE)
private List<String> msgContentListItem;
@Override
public Integer call() throws Exception {
return 0;
}
}
class MyTests {
MyMain main = new MyMain();
CommandLine commandLine = new CommandLine(main);
@Test
void test_item__null() {
commandLine.parseArgs("--item", "--item", "pepa");
// https://github.com/powermock/powermock/wiki/Bypass-Encapsulation
List<String> v = Whitebox.getInternalState(main, "msgContentListItem", main.getClass());
assertThat(v).containsExactly(null, "pepa");
}
} prints
|
Okay let me check. |
Away from PC, can you run with |
I'm thinking that the observations at the beginning of the answer https://stackoverflow.com/a/74275000/1047788 are relevant. |
You may have found a bug 🐛 I'll investigate when I get to my pc. |
"--item --item foo"
as [null, "foo"]
:List<String>
fallbackValue
NULL_VALUE does not work for Collection options (was: How do I get picocli to parse "--item --item foo"
as [null, "foo"]
:List<String>
)
I confirmed this is a bug and have a fix in progress. |
Thank you for raising this. |
Originally asked at https://stackoverflow.com/questions/74273941/how-do-i-get-picocli-to-parse-item-item-foo-as-null-foo-listst. Thinking about it more, I decided that this is a missing feature, with the only possibility being the workaround in the SO answer.
I'd like to propose adding a feature to make what I want more straightforward!
I have a parameter named
--msg-content-list-item
I wish for the following test to pass
But it doesn't and I get
How do I define
@CommandLine.Option
to behave the way I want?The text was updated successfully, but these errors were encountered: