jgvariant-tool: Factor out generic read command.
Change-Id: I977a3a36ae5dec7e5a2847b2d0558dd7026184b1
diff --git a/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java b/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java
index 7b25dfc..fe8211e 100644
--- a/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java
+++ b/jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java
@@ -6,6 +6,7 @@
import static java.util.logging.Level.*;
+import eu.mulk.jgvariant.core.Decoder;
import eu.mulk.jgvariant.ostree.Summary;
import eu.mulk.jgvariant.tool.jsonb.*;
import jakarta.json.bind.Jsonb;
@@ -72,15 +73,11 @@
name = "summary",
mixinStandardHelpOptions = true,
description = "Manipulate OSTree summary files.")
- static final class SummaryCommand extends BaseCommand {
+ static final class SummaryCommand extends BaseDecoderCommand<Summary> {
@Command(mixinStandardHelpOptions = true)
void read(@Parameters(paramLabel = "<file>") File file) throws IOException {
- LOG.fine(() -> "Reading file %s".formatted(file));
- var fileBytes = ByteBuffer.wrap(Files.readAllBytes(fs().getPath(file.getPath())));
- var decoder = Summary.decoder();
- var thing = decoder.decode(fileBytes);
- out().println(jsonb.toJson(thing));
+ read(file, Summary.decoder());
}
SummaryCommand() {}
@@ -111,5 +108,15 @@
}
}
+ abstract static class BaseDecoderCommand<T> extends BaseCommand {
+
+ protected final void read(File file, Decoder<T> decoder) throws IOException {
+ LOG.fine(() -> "Reading file %s".formatted(file));
+ var fileBytes = ByteBuffer.wrap(Files.readAllBytes(fs().getPath(file.getPath())));
+ var thing = decoder.decode(fileBytes);
+ out().println(jsonb.toJson(thing));
+ }
+ }
+
MainCommand() {}
}
diff --git a/jgvariant-tool/src/main/java/module-info.java b/jgvariant-tool/src/main/java/module-info.java
index 3f457ea..1e9cdf1 100644
--- a/jgvariant-tool/src/main/java/module-info.java
+++ b/jgvariant-tool/src/main/java/module-info.java
@@ -53,7 +53,7 @@
* }
* }
*/
- module eu.mulk.jgvariant.tool {
+module eu.mulk.jgvariant.tool {
requires transitive eu.mulk.jgvariant.ostree;
requires info.picocli;
requires jakarta.json;