diff --git a/emulator/src/main/java/kafka/cli/emulator/Cli.java b/emulator/src/main/java/kafka/cli/emulator/Cli.java index e618ed9..6bc197b 100644 --- a/emulator/src/main/java/kafka/cli/emulator/Cli.java +++ b/emulator/src/main/java/kafka/cli/emulator/Cli.java @@ -30,7 +30,7 @@ """, versionProvider = Cli.VersionProviderWithConfigProvider.class, mixinStandardHelpOptions = true, - subcommands = { Cli.RecordCommand.class, Cli.ReplayCommand.class } + subcommands = { Cli.InitCommand.class, Cli.RecordCommand.class, Cli.ReplayCommand.class } ) public class Cli implements Callable { @@ -45,6 +45,35 @@ public Integer call() { return 0; } + @CommandLine.Command( + name = "init", + description = """ + Initialize emualator archive file + """ + ) + static class InitCommand implements Callable { + + @CommandLine.Parameters( + index = "0", + description = """ + Path to emulator archive""", + defaultValue = "./kfk-emulator.db" + ) + Path archivePath; + + @Override + public Integer call() { + try { + final var store = new ArchiveStore.SqliteArchiveLoader(archivePath); + final var emu = new KafkaEmulator(store); + emu.init(); + return 0; + } catch (Exception e) { + e.printStackTrace(); + return 1; + } + } + } @CommandLine.Command( name = "record", description = """ diff --git a/emulator/src/main/java/kafka/cli/emulator/KafkaEmulator.java b/emulator/src/main/java/kafka/cli/emulator/KafkaEmulator.java index f796a0a..5b3f07b 100644 --- a/emulator/src/main/java/kafka/cli/emulator/KafkaEmulator.java +++ b/emulator/src/main/java/kafka/cli/emulator/KafkaEmulator.java @@ -37,6 +37,11 @@ public KafkaEmulator(ArchiveStore archiveLoader) { this.archiveLoader = archiveLoader; } + public void init() { + final var archive = EmulatorArchive.create(); + archiveLoader.save(archive); + } + /** * Read and package topics records into an archive. *