From ec2c34a3431835a34f88e5967a774f80c3e21d7d Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sat, 2 Mar 2024 13:48:04 +0100 Subject: jgvariant-tool: Factor out generic read command. Change-Id: I977a3a36ae5dec7e5a2847b2d0558dd7026184b1 --- .../main/java/eu/mulk/jgvariant/tool/MainCommand.java | 19 +++++++++++++------ jgvariant-tool/src/main/java/module-info.java | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'jgvariant-tool/src') 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 { @Command(mixinStandardHelpOptions = true) void read(@Parameters(paramLabel = "") 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 extends BaseCommand { + + protected final void read(File file, Decoder 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; -- cgit v1.2.3