diff options
author | axtloss <axtlos@getcryst.al> | 2023-05-24 23:43:57 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2023-05-24 23:43:57 +0200 |
commit | 44ea7455e1f440a8df4070604213b390c21e7a3d (patch) | |
tree | 8c0cb535f4cb3588ef8bd610edfb418e15ec0ff2 /src/main/java/io/github/jshipit/JshipIT.java | |
parent | a881b5319b1a7d03f476231df9c8491fb4cdd451 (diff) | |
download | jshipit-44ea7455e1f440a8df4070604213b390c21e7a3d.tar.gz jshipit-44ea7455e1f440a8df4070604213b390c21e7a3d.tar.bz2 |
Add command line options
Diffstat (limited to 'src/main/java/io/github/jshipit/JshipIT.java')
-rwxr-xr-x | src/main/java/io/github/jshipit/JshipIT.java | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/src/main/java/io/github/jshipit/JshipIT.java b/src/main/java/io/github/jshipit/JshipIT.java index 5ccd96e..d51ddbe 100755 --- a/src/main/java/io/github/jshipit/JshipIT.java +++ b/src/main/java/io/github/jshipit/JshipIT.java @@ -1,51 +1,40 @@ package io.github.jshipit; +import com.beust.jcommander.JCommander; import com.fasterxml.jackson.databind.JsonNode; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import com.beust.jcommander.Parameter; public class JshipIT { - public JshipIT() { - /* - DockerAPIHelper api = new DockerAPIHelper("registry.getcryst.al","crystal/misc", "docker", "latest"); - JsonNode manifest = null; - - System.out.println("API Token: " + api.getApiToken()); - try { - manifest = api.fetchManifestJson(); - } catch (IOException ignored) {} // Proper error handling is bloat - - System.out.println("Manifest: " + manifest); - - Path path = Path.of("./tmp_"+api.getImage()+"_"+api.getTag()); - try { - Files.createDirectory(path); - } catch (IOException e) { - System.out.println("Failed to create directory: " + path); - e.printStackTrace(); - return; - } + public JshipIT(String[] args) { - assert manifest != null; - JsonNode layers = manifest.get("layers"); - for (JsonNode layer : layers) { - System.out.println("Layer: " + layer); - try { - api.fetchBlob(layer.get("digest").asText(), path.toString()); - } catch (IOException e) { - e.printStackTrace(); - } - } + CommandCreate commandCreate = new CommandCreate(); + CommandPull commandPull = new CommandPull(); + JCommander commands = JCommander.newBuilder() + .addCommand("create", commandCreate) + .addCommand("pull", commandPull) + .build(); - */ + commands.parse(args); OCIDataStore dataStore = new OCIDataStore("./tmp"); - //dataStore.createImage("registry.docker.io","library", "bash", "devel-alpine3.18"); - ContainerManager containerManager = new ContainerManager("testContainer", "bash", "devel-alpine3.18", "bash", "registry.docker.io", "library", dataStore); - containerManager.createContainer(); - containerManager.startContainer(); + + if (commands.getParsedCommand() == null) { + commands.usage(); + System.exit(1); + } else if (commands.getParsedCommand().equals("create")) { + ContainerManager containerManager = new ContainerManager(commandCreate.containerName, commandCreate.containerImage, commandCreate.containerTag, "bash", commandCreate.containerApiRepo, commandCreate.containerRepo, dataStore); + containerManager.createContainer(); + containerManager.startContainer(); + } else if (commands.getParsedCommand().equals("pull")) { + dataStore.createImage(commandPull.containerApiRepo, commandPull.containerRepo, commandPull.containerImage, commandPull.containerTag); + } + + + } }
\ No newline at end of file |