PicoCli Mutually Dependent Options 问题(解析值)
PicoCli Mutually Dependent Options question (resolve values)
我有下面的代码。
我的用例是,当使用选项 --install 时,您还必须使用选项 --version。这在使用以下依赖组时效果很好。
但是我无法获取变量版本的值。我怎么extract/resolve呢?
有什么方法可以通过 call() 方法实现吗?
@CommandLine.Command(name = "rt")
@Component
public class Artifactory implements Callable<Integer> {
@CommandLine.ArgGroup(exclusive = false)
Dependent dependent;
static class Dependent{
@CommandLine.Option(names = {"-i", "--install"}, description = "The Artifactory version")
boolean install;
@CommandLine.Option(names = {"-v", "--version"}, required = false, description = "The Artifactory version")
String version;
}
@Override
public Integer call() throws Exception {
System.out.println("We are installing Artifactory version from @Artifactory: " + version);
return 0;
}
}
感谢您的帮助:D
您应该能够从 Artifactory
class 的 dependent
字段中获取指定的值。例如:
@Command(name = "rt")
@Component
public class Artifactory implements Callable<Integer> {
@ArgGroup(exclusive = false, multiplicity = "1")
Dependent dependent;
static class Dependent{
@Option(names = {"-i", "--install"}, description = "Install or not.")
boolean install;
@Option(names = {"-v", "--version"}, required = false,
description = "The Artifactory version.")
String version;
}
@Override
public Integer call() throws Exception {
// I made the arg-group multiplicity=1, so it cannot be `null`.
// The default is `multiplicity = "0..1"`;
// in that case you need to check that dependent != null (if the group was not specified).
System.out.printf(
"We are %sinstalling Artifactory version %s%n",
(dependent.install ? "" : "not "), dependent.version);
return 0;
}
}
我有下面的代码。
我的用例是,当使用选项 --install 时,您还必须使用选项 --version。这在使用以下依赖组时效果很好。
但是我无法获取变量版本的值。我怎么extract/resolve呢? 有什么方法可以通过 call() 方法实现吗?
@CommandLine.Command(name = "rt")
@Component
public class Artifactory implements Callable<Integer> {
@CommandLine.ArgGroup(exclusive = false)
Dependent dependent;
static class Dependent{
@CommandLine.Option(names = {"-i", "--install"}, description = "The Artifactory version")
boolean install;
@CommandLine.Option(names = {"-v", "--version"}, required = false, description = "The Artifactory version")
String version;
}
@Override
public Integer call() throws Exception {
System.out.println("We are installing Artifactory version from @Artifactory: " + version);
return 0;
}
}
感谢您的帮助:D
您应该能够从 Artifactory
class 的 dependent
字段中获取指定的值。例如:
@Command(name = "rt")
@Component
public class Artifactory implements Callable<Integer> {
@ArgGroup(exclusive = false, multiplicity = "1")
Dependent dependent;
static class Dependent{
@Option(names = {"-i", "--install"}, description = "Install or not.")
boolean install;
@Option(names = {"-v", "--version"}, required = false,
description = "The Artifactory version.")
String version;
}
@Override
public Integer call() throws Exception {
// I made the arg-group multiplicity=1, so it cannot be `null`.
// The default is `multiplicity = "0..1"`;
// in that case you need to check that dependent != null (if the group was not specified).
System.out.printf(
"We are %sinstalling Artifactory version %s%n",
(dependent.install ? "" : "not "), dependent.version);
return 0;
}
}