forked from AdamBien/lightmetal
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlmlist
More file actions
executable file
·69 lines (55 loc) · 1.65 KB
/
Copy pathlmlist
File metadata and controls
executable file
·69 lines (55 loc) · 1.65 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
63
64
65
66
67
68
69
#!/usr/bin/env -S java --enable-native-access=ALL-UNNAMED --source 25 -cp ./zbo/lightmetal.jar:./lightmetal.jar
import lm.catalog.boundary.ModelCatalog;
import lm.catalog.control.ModelsDirectory;
import lm.configuration.control.ZCfg;
String name = MethodHandles.lookup().lookupClass().getName();
String version = "2026-06-07.1";
void main(String... args) throws Exception {
if (args.length > 0 && args[0].equals("-version")) {
IO.println(name + " " + version);
return;
}
ZCfg.load("lightmetal");
var models = ModelCatalog.list();
if (models.isEmpty()) {
System.err.println(name + ": no models found in " + ModelsDirectory.path());
System.exit(1);
}
var activeName = activeModelFileName();
models.forEach(m -> printModel(m, activeName));
}
String activeModelFileName() {
var configured = ZCfg.string("model");
if (configured == null || configured.isBlank()) {
return null;
}
return configured;
}
void printModel(String fileName, String activeName) {
if (fileName.equals(activeName)) {
Log.active("* " + fileName);
} else {
IO.println(" " + fileName);
}
}
enum Log {
ACTIVE(Color.GREEN);
enum Color {
GREEN("[38;2;133;153;0m");
String code;
Color(String code) {
this.code = code;
}
}
static final String RESET = "[0m";
String value;
Log(Color color) {
this.value = color.code + "%s" + RESET;
}
void out(String message) {
System.out.println(value.formatted(message));
}
public static void active(String message) {
Log.ACTIVE.out(message);
}
}