Merge pull request #3167 from hengyunabc/master

fix cli @Option acceptValue support.
This commit is contained in:
Thomas Segismont
2019-11-18 12:30:51 +01:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -376,7 +376,9 @@ public class Option {
*/
public Option setFlag(boolean flag) {
this.flag = flag;
setSingleValued(false);
if (flag) {
setSingleValued(false);
}
return this;
}

View File

@@ -192,6 +192,7 @@ public class CLIConfiguratorTest {
CLIConfigurator.inject(evaluatedCLI, command);
assertThat(command.aBoolean).isTrue();
assertThat(command.acceptValueBoolean).isTrue();
assertThat(command.aShort).isEqualTo((short) 1);
assertThat(command.aByte).isEqualTo((byte) 1);
assertThat(command.anInt).isEqualTo(1);
@@ -201,11 +202,12 @@ public class CLIConfiguratorTest {
assertThat(command.aChar).isEqualTo('c');
assertThat(command.aString).isEqualTo("hello");
evaluatedCLI = parse(cli, "--boolean2", "--short2=1", "--byte2=1", "--int2=1", "--long2=1",
evaluatedCLI = parse(cli, "--boolean2", "--acceptValueBoolean=false", "--short2=1", "--byte2=1", "--int2=1", "--long2=1",
"--double2=1.1", "--float2=1.1", "--char2=c", "--string=hello");
CLIConfigurator.inject(evaluatedCLI, command);
assertThat(command.anotherBoolean).isTrue();
assertThat(command.acceptValueBoolean).isFalse();
assertThat(command.anotherShort).isEqualTo((short) 1);
assertThat(command.anotherByte).isEqualTo((byte) 1);
assertThat(command.anotherInt).isEqualTo(1);
@@ -215,6 +217,13 @@ public class CLIConfiguratorTest {
assertThat(command.anotherChar).isEqualTo('c');
assertThat(command.aString).isEqualTo("hello");
evaluatedCLI = parse(cli, "--acceptValueBoolean=xxx");
CLIConfigurator.inject(evaluatedCLI, command);
assertThat(command.acceptValueBoolean).isFalse();
evaluatedCLI = parse(cli, "--acceptValueBoolean=true");
CLIConfigurator.inject(evaluatedCLI, command);
assertThat(command.acceptValueBoolean).isTrue();
evaluatedCLI = parse(cli, "--state=NEW");
CLIConfigurator.inject(evaluatedCLI, command);
assertThat(command.aState).isEqualTo(Thread.State.NEW);
@@ -400,6 +409,7 @@ public class CLIConfiguratorTest {
Thread.State aState;
boolean aBoolean;
boolean acceptValueBoolean;
Boolean anotherBoolean;
byte aByte;
@@ -433,6 +443,12 @@ public class CLIConfiguratorTest {
this.aBoolean = aBoolean;
}
@io.vertx.core.cli.annotations.Option(longName = "acceptValueBoolean", flag = false, acceptValue = true)
@DefaultValue("true")
public void setAcceptValueBoolean(boolean acceptValueBoolean) {
this.acceptValueBoolean = acceptValueBoolean;
}
@io.vertx.core.cli.annotations.Option(longName = "byte", shortName = "B")
public void setaByte(byte aByte) {
this.aByte = aByte;