Skip to content

Commit fcc17d6

Browse files
authored
added optional search key to listCacheItems (#117)
1 parent 665939c commit fcc17d6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/cache/ListCacheItems.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
import java.util.Collections;
77
import java.util.Map;
8+
import java.util.regex.Pattern;
89

910
import com.oracle.weblogic.imagetool.api.model.CommandResponse;
1011
import com.oracle.weblogic.imagetool.util.Constants;
1112
import com.oracle.weblogic.imagetool.util.Utils;
1213
import picocli.CommandLine.Command;
14+
import picocli.CommandLine.Option;
1315

1416
@Command(
1517
name = "listItems",
@@ -33,10 +35,19 @@ public CommandResponse call() {
3335
System.out.println(Constants.CACHE_DIR_KEY + "=" + cacheDir);
3436
resultMap.remove(Constants.CACHE_DIR_KEY);
3537
}
36-
resultMap.forEach((key, value) -> System.out.println(key + "=" + value));
38+
39+
Pattern pattern = Pattern.compile(key == null ? ".*" : key);
40+
resultMap.entrySet().stream()
41+
.filter(entry -> pattern.matcher(entry.getKey()).matches())
42+
.forEach(System.out::println);
3743

3844
return new CommandResponse(0, "Cache contents", resultMap);
3945
}
4046
}
4147

48+
@Option(
49+
names = {"--key"},
50+
description = "list only cached items where the key matches this regex"
51+
)
52+
private String key;
4253
}

0 commit comments

Comments
 (0)