From 269df0e52e18c9dbd919a5a5b8934a37b5300ad1 Mon Sep 17 00:00:00 2001 From: Munish Chouhan Date: Tue, 21 May 2024 20:01:30 +0200 Subject: [PATCH] Add --name-strategy option to wave cli (#71) --- app/build.gradle | 2 +- app/src/main/java/io/seqera/wave/cli/App.java | 15 +++------ .../groovy/io/seqera/wave/cli/AppTest.groovy | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 701650c..44adf0c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,7 @@ repositories { } dependencies { - implementation 'io.seqera:wave-api:0.9.1' + implementation 'io.seqera:wave-api:0.10.0' implementation 'io.seqera:wave-utils:0.12.0' implementation 'info.picocli:picocli:4.6.1' implementation 'com.squareup.moshi:moshi:1.15.0' diff --git a/app/src/main/java/io/seqera/wave/cli/App.java b/app/src/main/java/io/seqera/wave/cli/App.java index 0ce3ad8..e8e07f7 100644 --- a/app/src/main/java/io/seqera/wave/cli/App.java +++ b/app/src/main/java/io/seqera/wave/cli/App.java @@ -40,15 +40,7 @@ import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; -import io.seqera.wave.api.BuildContext; -import io.seqera.wave.api.ContainerConfig; -import io.seqera.wave.api.ContainerInspectRequest; -import io.seqera.wave.api.ContainerInspectResponse; -import io.seqera.wave.api.ContainerLayer; -import io.seqera.wave.api.PackagesSpec; -import io.seqera.wave.api.ServiceInfo; -import io.seqera.wave.api.SubmitContainerTokenRequest; -import io.seqera.wave.api.SubmitContainerTokenResponse; +import io.seqera.wave.api.*; import io.seqera.wave.cli.exception.BadClientResponseException; import io.seqera.wave.cli.exception.ClientConnectionException; import io.seqera.wave.cli.exception.IllegalCliArgumentException; @@ -199,6 +191,9 @@ public class App implements Runnable { @Option(names = {"--include"}, paramLabel = "false", description = "Include one or more containers in the specified base image") private List includes; + @Option(names = {"--name-strategy"}, paramLabel = "false", description = "Specify the name strategy for the container name, it can be 'none' or 'tagPrefix' or 'imageSuffix'") + private ImageNameStrategy nameStrategy; + @CommandLine.Parameters List prompt; @@ -419,7 +414,7 @@ protected SubmitContainerTokenRequest createRequest() { .withFreezeMode(freeze) .withDryRun(dryRun) .withContainerIncludes(includes) - ; + .withNameStrategy(nameStrategy); } public void inspect() { diff --git a/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy b/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy index ec5128b..4ad611a 100644 --- a/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy +++ b/app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy @@ -17,6 +17,7 @@ package io.seqera.wave.cli +import io.seqera.wave.api.ImageNameStrategy import io.seqera.wave.cli.util.DurationConverter import java.nio.file.Files @@ -340,4 +341,36 @@ class AppTest extends Specification { app.prompt == ['Get a docker container'] } + def 'should get the correct name strategy'(){ + given: + def app = new App() + String[] args = ["-i", "ubuntu:latest", "--name-strategy", "tagPrefix"] + + when: + def cli = new CommandLine(app) + cli.parseArgs(args) + and: + app.validateArgs() + then: + noExceptionThrown() + and: + app.@nameStrategy == ImageNameStrategy.tagPrefix + } + + def 'should fail when passing incorrect name strategy'(){ + given: + def app = new App() + String[] args = ["-i", "ubuntu:latest", "--name-strategy", "wrong"] + + when: + def cli = new CommandLine(app) + cli.parseArgs(args) + and: + app.validateArgs() + then: + def e = thrown(CommandLine.ParameterException) + and: + e.getMessage() == "Invalid value for option '--name-strategy': expected one of [none, tagPrefix, imageSuffix] (case-sensitive) but was 'wrong'" + } + }