-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathproperties.java
More file actions
executable file
·62 lines (50 loc) · 2.02 KB
/
properties.java
File metadata and controls
executable file
·62 lines (50 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.7.7
//DEPS de.vandermeer:asciitable:0.3.2
//DEPS org.jline:jline:3.30.6
import de.vandermeer.asciitable.*;
import de.vandermeer.asciithemes.a7.A7_Grids;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static java.lang.System.*;
import static java.lang.System.getProperties;
import static java.lang.System.out;
@Command(name = "properties", mixinStandardHelpOptions = true, version = "properties 0.1",
description = "Dump java properties made with jbang")
class properties implements Callable<Integer> {
@Parameters(description = "Pattern used to filter System properties", defaultValue = ".*")
private List<Pattern> pattern;
public static void main(String... args) {
int exitCode = new CommandLine(new properties()).execute(args);
exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
int[] maxkey = { 0 };
AsciiTable at = new AsciiTable();
at.getContext().setGrid(A7_Grids.minusBarPlusEquals());
at.addRule();
at.addRow("Key", "Value");
at.addRule();
getProperties().keySet().stream().sorted()
.filter(x -> pattern.stream().anyMatch(y -> y.matcher((String) x).find()))
.forEach(x -> {
maxkey[0] = Math.max(maxkey[0], ((String) x).length());
at.addRow(x, getProperty((String) x));
});
at.addRule();
int colwidth = org.jline.terminal.TerminalBuilder.terminal().getWidth();
if(colwidth==0) colwidth = 80;
at.getRenderer().setCWC(new CWC_LongestWordMax(colwidth - maxkey[0] - 3));
out.println(at.render(colwidth));
return 0;
}
}