-
Notifications
You must be signed in to change notification settings - Fork 9
/
env.java
executable file
·66 lines (53 loc) · 2.12 KB
/
env.java
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
63
64
65
66
//usr/bin/env echo '
/**** BOOTSTRAP jbang ****'>/dev/null
command -v jbang >/dev/null 2>&1 || curl -Ls https://sh.jbang.dev | bash -s app setup
exec jbang "$0" "$@" ; exit $?
\*** IMPORTANT: Any code including imports and annotations must come after this line ***/
//usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.7.5
//DEPS de.vandermeer:asciitable:0.3.2
//DEPS org.jline:jline:3.23.0
import de.vandermeer.asciitable.*;
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 = "env 0.1",
description = "Dump java properties made with jbang")
class env implements Callable<Integer> {
@Parameters(description = "Pattern used to filter env", defaultValue = ".*")
private List<Pattern> pattern;
public static void main(String... args) {
int exitCode = new CommandLine(new env()).execute(args);
exit(exitCode);
}
@Override
public Integer call() throws Exception { // your business logic goes here...
int[] maxkey = { 0 };
AsciiTable at = new AsciiTable();
at.addRule();
at.addRow("Key", "Value");
at.addRule();
getenv().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, getenv((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;
}
}