This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4883ad3
commit e8f6c80
Showing
8 changed files
with
113 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Tcin[]> { | ||
@Override | ||
public Tcin[] convert(String s) throws ThreshrException { | ||
return new Tcin[]{new Tcin(s.split(","))}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=<tcinValues>]...\n" + | ||
" -h, --help Show this help message and exit.\n" + | ||
" -t, --tcin, product-id-number=<tcinValues>\n" + | ||
"\n" + | ||
" -V, --version Print version information and exit.\n" | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters