diff --git a/pom.xml b/pom.xml
index 3f3bdf1..81e2b11 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,13 +4,13 @@
4.0.0
com.graqr
threshr
- 0.0.12
+ 0.0.13-SNAPSHOT
${packaging}
io.micronaut.platform
micronaut-parent
- 4.4.1
+ 4.4.2
@@ -44,6 +44,16 @@
+
+ info.picocli
+ picocli
+ compile
+
+
+ io.micronaut.picocli
+ micronaut-picocli
+ compile
+
ch.qos.logback
logback-classic
@@ -127,7 +137,6 @@
42.7.2
test
-
diff --git a/src/main/java/com/graqr/threshr/ThreshrCli.java b/src/main/java/com/graqr/threshr/ThreshrCli.java
new file mode 100644
index 0000000..51c1951
--- /dev/null
+++ b/src/main/java/com/graqr/threshr/ThreshrCli.java
@@ -0,0 +1,40 @@
+package com.graqr.threshr;
+
+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 {
+
+ ThreshrController controller;
+ @Option(
+ names = {"--tcin", "-t", "product-id-number"},
+ required = false,
+ description = "", converter = TcinsConverter.class)
+ Tcin[] tcinValues;
+
+ public ThreshrCli(ThreshrController threshr) {
+ this.controller = 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 {
+ @Override
+ public Tcin[] convert(String s) throws ThreshrException {
+ return new Tcin[]{new Tcin(s.split(","))};
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/com/graqr/threshr/Threshr.java b/src/main/java/com/graqr/threshr/ThreshrController.java
similarity index 97%
rename from src/main/java/com/graqr/threshr/Threshr.java
rename to src/main/java/com/graqr/threshr/ThreshrController.java
index 914fad7..7b393da 100644
--- a/src/main/java/com/graqr/threshr/Threshr.java
+++ b/src/main/java/com/graqr/threshr/ThreshrController.java
@@ -17,12 +17,12 @@
import java.util.List;
@Controller("/constructor")
-public class Threshr {
+public class ThreshrController {
private final ThreshrClient threshrClient;
@Inject
- public Threshr(@SuppressWarnings("ClassEscapesDefinedScope") ThreshrClient threshrClient){
+ public ThreshrController(@SuppressWarnings("ClassEscapesDefinedScope") ThreshrClient threshrClient){
this.threshrClient = threshrClient;
}
diff --git a/src/main/java/com/graqr/threshr/model/queryparam/Place.java b/src/main/java/com/graqr/threshr/model/queryparam/Place.java
index b26536c..edd6066 100644
--- a/src/main/java/com/graqr/threshr/model/queryparam/Place.java
+++ b/src/main/java/com/graqr/threshr/model/queryparam/Place.java
@@ -1,11 +1,12 @@
package com.graqr.threshr.model.queryparam;
+import com.graqr.threshr.ThreshrController;
import io.micronaut.serde.annotation.Serdeable;
import lombok.Data;
/**
* Place is a query parameter used when querying nearby target store locations. The query accepts either a zipcode
- * or a city-state combo. See {@link com.graqr.threshr.Threshr#getStores(Place)}
+ * or a city-state combo. See {@link ThreshrController#getStores(Place)}
*/
@Serdeable
@Data
diff --git a/src/test/groovy/com/graqr/threshr/ThreshrCliSpec.groovy b/src/test/groovy/com/graqr/threshr/ThreshrCliSpec.groovy
new file mode 100644
index 0000000..ad74c83
--- /dev/null
+++ b/src/test/groovy/com/graqr/threshr/ThreshrCliSpec.groovy
@@ -0,0 +1,54 @@
+package com.graqr.threshr
+
+import io.micronaut.configuration.picocli.PicocliRunner
+import io.micronaut.context.ApplicationContext
+import io.micronaut.context.env.Environment
+import spock.lang.AutoCleanup
+import spock.lang.Shared
+
+class ThreshrCliSpec extends ThreshrSpec {
+
+ @Shared
+ final PrintStream originalOut = System.out
+ @Shared
+ final PrintStream originalErr = System.err
+
+ @Shared
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
+ ByteArrayOutputStream errStream = new ByteArrayOutputStream()
+
+
+ @Shared
+ @AutoCleanup
+ ApplicationContext ctx = ApplicationContext.run(Environment.CLI, Environment.TEST)
+
+ void execute(String... args) {
+ 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:
+ outputStream.toString() ==
+ "Usage: threshr grocery query tool [-hV] [-t=]...\n" +
+ " -h, --help Show this help message and exit.\n" +
+ " -t, --tcin, product-id-number=\n" +
+ "\n" +
+ " -V, --version Print version information and exit.\n"
+
+ }
+}
diff --git a/src/test/groovy/com/graqr/threshr/ThreshrClientSpec.groovy b/src/test/groovy/com/graqr/threshr/ThreshrControllerClientSpec.groovy
similarity index 97%
rename from src/test/groovy/com/graqr/threshr/ThreshrClientSpec.groovy
rename to src/test/groovy/com/graqr/threshr/ThreshrControllerClientSpec.groovy
index 3f5e270..1188c1a 100644
--- a/src/test/groovy/com/graqr/threshr/ThreshrClientSpec.groovy
+++ b/src/test/groovy/com/graqr/threshr/ThreshrControllerClientSpec.groovy
@@ -12,7 +12,7 @@ import java.util.stream.Collectors
* This test class is necessary despite similarity to the controller test. please don't delete this as the
* httpclient logs are visible in this test but not in the controller test.
*/
-class ThreshrClientSpec extends ThreshrSpec {
+class ThreshrControllerClientSpec extends ThreshrSpec {
void "no error requesting product summaries"() {
diff --git a/src/test/groovy/com/graqr/threshr/ThreshrControllerSpec.groovy b/src/test/groovy/com/graqr/threshr/ThreshrControllerControllerSpec.groovy
similarity index 98%
rename from src/test/groovy/com/graqr/threshr/ThreshrControllerSpec.groovy
rename to src/test/groovy/com/graqr/threshr/ThreshrControllerControllerSpec.groovy
index c85f0f8..2ceb960 100644
--- a/src/test/groovy/com/graqr/threshr/ThreshrControllerSpec.groovy
+++ b/src/test/groovy/com/graqr/threshr/ThreshrControllerControllerSpec.groovy
@@ -10,7 +10,7 @@ import io.micronaut.test.extensions.spock.annotation.MicronautTest
import spock.lang.Shared
@MicronautTest
-class ThreshrControllerSpec extends ThreshrSpec {
+class ThreshrControllerControllerSpec extends ThreshrSpec {
@Shared
@Value('${test.datasources.default.url}')
diff --git a/src/test/groovy/com/graqr/threshr/ThreshrSpec.groovy b/src/test/groovy/com/graqr/threshr/ThreshrSpec.groovy
index 0b0f922..4020aa0 100644
--- a/src/test/groovy/com/graqr/threshr/ThreshrSpec.groovy
+++ b/src/test/groovy/com/graqr/threshr/ThreshrSpec.groovy
@@ -18,7 +18,7 @@ class ThreshrSpec extends Specification {
// ----------- Resources / Fields -----------
@Inject
@Shared
- Threshr threshrController
+ ThreshrController threshrController
@Inject
@Shared