-
Notifications
You must be signed in to change notification settings - Fork 9
/
catalog2readme.java
executable file
·74 lines (58 loc) · 2.15 KB
/
catalog2readme.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
67
68
69
70
71
72
73
74
///usr/bin/env jbang "$0" "$@" ; exit $?
// Update the Quarkus version to what you want here or run jbang with
// `-Dquarkus.version=<version>` to override it.
//DEPS io.quarkus:quarkus-bom:${quarkus.version:3.5.0}@pom
//DEPS io.quarkus:quarkus-picocli
//DEPS io.quarkus:quarkus-jackson
//DEPS io.quarkus:quarkus-qute
//Q:CONFIG quarkus.banner.enabled=false
//Q:CONFIG quarkus.log.level=WARN
//Q:CONFIG quarkus.qute.property-not-found-strategy=throw-exception
//FILES templates/index.txt=index.txt.qute
import java.io.File;
import java.io.IOException;
import java.util.Map;
import jakarta.inject.Inject;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import io.quarkus.qute.Template;
import picocli.CommandLine;
@CommandLine.Command
public class catalog2readme implements Runnable {
@CommandLine.Parameters(index = "0", description = "The file to print", defaultValue = "jbang-catalog.json")
File file;
@CommandLine.Option(names = "-l", required = false)
String location;
@Inject
CommandLine.IFactory factory;
final ObjectMapper mapper;
@Inject
Template index;
public catalog2readme(ObjectMapper mapper) {
this.mapper = mapper;
mapper// .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES,true)
.setPropertyNamingStrategy(PropertyNamingStrategy.KEBAB_CASE)
.setVisibility(PropertyAccessor.FIELD, Visibility.ANY);
}
@Override
public void run() {
try {
Catalog catalog;
catalog = mapper.readValue(file, Catalog.class);
System.out.println(index.data("catalog", catalog).data("location", location).render());
} catch (IOException e) {
e.printStackTrace();
}
}
static public class Catalog {
public Map<String, Alias> aliases;
public String baseRef;
public String description;
}
static public class Alias {
public String scriptRef;
public String description;
}
}