aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-tool/src/main/java/eu
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <code@mail.matthias.benkard.de>2024-03-02 13:48:04 +0100
committerMatthias Andreas Benkard <code@mail.matthias.benkard.de>2024-03-02 13:48:04 +0100
commitec2c34a3431835a34f88e5967a774f80c3e21d7d (patch)
tree29bb0027cf86b7ee967e73fe2b777e18903a5178 /jgvariant-tool/src/main/java/eu
parent08ecdd63d09161e0da02f47a055dda5ca7562bcc (diff)
jgvariant-tool: Factor out generic read command.
Change-Id: I977a3a36ae5dec7e5a2847b2d0558dd7026184b1
Diffstat (limited to 'jgvariant-tool/src/main/java/eu')
-rw-r--r--jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java19
1 files changed, 13 insertions, 6 deletions
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 @@ package eu.mulk.jgvariant.tool;
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 @@ final class MainCommand {
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 @@ final class MainCommand {
}
}
+ 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() {}
}