Skip to content

Commit

Permalink
wip: add ThreshrCli & Spec.
Browse files Browse the repository at this point in the history
copy over application.yaml from core
  • Loading branch information
Jonathan-Zollinger committed Jun 10, 2024
1 parent ea4d910 commit 158e89c
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 24 deletions.
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<micronaut.test.resources.enabled>true</micronaut.test.resources.enabled>
<micronaut.aot.enabled>false</micronaut.aot.enabled>
<micronaut.aot.packageName>com.graqr.aot.generated</micronaut.aot.packageName>
<exec.mainClass>com.graqr.Application</exec.mainClass>
<exec.mainClass>com.graqr.ThreshrCli</exec.mainClass>
</properties>
<repositories>
<repository>
Expand Down
10 changes: 0 additions & 10 deletions cli/src/main/java/com/graqr/Application.java

This file was deleted.

43 changes: 43 additions & 0 deletions cli/src/main/java/com/graqr/ThreshrCli.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.graqr;

import com.graqr.threshr.Threshr;
import com.graqr.threshr.ThreshrException;
import com.graqr.threshr.model.queryparam.Tcin;
import io.micronaut.configuration.picocli.PicocliRunner;
import jakarta.inject.Singleton;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Singleton
@Command(name = "threshr grocery query tool", mixinStandardHelpOptions = true)
public class ThreshrCli implements Runnable {

Threshr threshr;

@Option(
names = {"--tcin", "-t", "product-id-number"},
required = false,
description = "", converter = TcinsConverter.class)
Tcin[] tcinValues;

public ThreshrCli(Threshr threshr) {
this.threshr = threshr;
}


public static void main(String[] args) {
PicocliRunner.run(ThreshrCli.class, args);
}

public void run() {
// TODO: do all the things :P
}

static class TcinsConverter implements CommandLine.ITypeConverter<Tcin[]> {
@Override
public Tcin[] convert(String s) throws ThreshrException {
return new Tcin[]{new Tcin(s.split(","))};
}
}
}
6 changes: 0 additions & 6 deletions cli/src/main/resources/application.properties

This file was deleted.

19 changes: 19 additions & 0 deletions cli/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
micronaut:
application:
name: threshr-cli
---
datasources:
default:
driver-class-name: org.postgresql.Driver
db-type: postgres
schema-generate: CREATE_DROP
dialect: POSTGRES
---
threshr:
key:
channel:
---
test:
datasources:
default:
url:
44 changes: 37 additions & 7 deletions cli/src/test/groovy/com/graqr/ThreshrCliSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
package com.graqr

import io.micronaut.runtime.EmbeddedApplication
import io.micronaut.configuration.picocli.PicocliRunner
import io.micronaut.context.ApplicationContext
import io.micronaut.context.env.Environment
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import spock.lang.Shared
import spock.lang.Specification

@MicronautTest
class ThreshrCliSpec extends Specification {

@Inject
EmbeddedApplication<?> application

void 'test it works'() {
expect:
application.running
@Shared
final PrintStream originalOut = System.out
@Shared
final PrintStream originalErr = System.err

@Shared
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
ByteArrayOutputStream errStream = new ByteArrayOutputStream()

void execute(String... args) {
try(ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST) as ApplicationContext) {
PicocliRunner.run(ThreshrCli, ctx, args)
}
}


def setup() {
outputStream.reset()
errStream.reset()
System.setOut(new PrintStream(outputStream))
System.setErr(new PrintStream(errStream))
}

def cleanup() {
System.setOut(originalOut)
System.setErr(originalErr)
}

def "cli help can be queried successfully"(){
when:
execute('--help')
then:
errStream.toString().trim().contains('Usage:')
}

}

0 comments on commit 158e89c

Please sign in to comment.