Skip to content

Commit

Permalink
Add --name-strategy option to wave cli (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
munishchouhan committed May 21, 2024
1 parent ed3c0be commit 269df0e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 5 additions & 10 deletions app/src/main/java/io/seqera/wave/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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<String> prompt;

Expand Down Expand Up @@ -419,7 +414,7 @@ protected SubmitContainerTokenRequest createRequest() {
.withFreezeMode(freeze)
.withDryRun(dryRun)
.withContainerIncludes(includes)
;
.withNameStrategy(nameStrategy);
}

public void inspect() {
Expand Down
33 changes: 33 additions & 0 deletions app/src/test/groovy/io/seqera/wave/cli/AppTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'"
}

}

0 comments on commit 269df0e

Please # to comment.