HDDS-1894. Add filter to scmcli listPipelines. (#1286)

This commit is contained in:
Li Cheng 2019-08-16 14:33:04 +08:00 committed by Sammi Chen
parent 5882cf94ea
commit bf3751521b
1 changed files with 23 additions and 1 deletions

View File

@ -38,11 +38,33 @@ public class ListPipelinesSubcommand implements Callable<Void> {
@CommandLine.ParentCommand @CommandLine.ParentCommand
private SCMCLI parent; private SCMCLI parent;
@CommandLine.Option( names = {"-ffc", "--filterByFactor"},
description = "Filter listed pipelines by Factor(ONE/one)", defaultValue = "",
required = false)
private String factor;
@CommandLine.Option( names = {"-fst", "--filterByState"},
description = "Filter listed pipelines by State(OPEN/CLOSE)", defaultValue = "",
required = false)
private String state;
@Override @Override
public Void call() throws Exception { public Void call() throws Exception {
try (ScmClient scmClient = parent.createScmClient()) { try (ScmClient scmClient = parent.createScmClient()) {
if (isNullOrEmpty(factor) && isNullOrEmpty(state)) {
scmClient.listPipelines().forEach(System.out::println); scmClient.listPipelines().forEach(System.out::println);
} else {
scmClient.listPipelines().stream()
.filter(p -> ((isNullOrEmpty(factor) || (p.getFactor().toString().compareToIgnoreCase(factor) == 0))
&& (isNullOrEmpty(state) || (p.getPipelineState().toString().compareToIgnoreCase(state) == 0))))
.forEach(System.out::println);
}
return null; return null;
} }
} }
protected static boolean isNullOrEmpty(String str) {
return ((str == null) || str.trim().isEmpty());
}
} }