aboutsummaryrefslogtreecommitdiff
path: root/jgvariant-tool/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'jgvariant-tool/src/main/java')
-rw-r--r--jgvariant-tool/src/main/java/eu/mulk/jgvariant/tool/MainCommand.java19
-rw-r--r--jgvariant-tool/src/main/java/module-info.java2
2 files changed, 14 insertions, 7 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() {}
}
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;