11package com .mindee .v2 .cli ;
22
3- import com .fasterxml .jackson .databind .ObjectMapper ;
4- import com .fasterxml .jackson .databind .SerializationFeature ;
53import com .mindee .input .LocalInputSource ;
64import com .mindee .v2 .MindeeClient ;
75import com .mindee .v2 .parsing .CommonResponse ;
86import java .io .File ;
97import java .util .List ;
10- import java .util .concurrent .Callable ;
118import picocli .CommandLine .Option ;
129import picocli .CommandLine .Parameters ;
1310
1411/**
1512 * Abstract base class for V2 inference CLI commands.
1613 * Handles common options (path, model-id, api-key, alias, output) and output formatting.
1714 */
18- public abstract class BaseInferenceCommand implements Callable < Integer > {
15+ public abstract class BaseInferenceCommand extends BaseCommand {
1916
2017 @ Parameters (index = "0" , paramLabel = "<path>" , description = "The path of the file to parse" )
2118 protected File file ;
2219
2320 @ Option (names = { "-m" , "--model-id" }, description = "ID of the model to use" , required = true )
2421 protected String modelId ;
2522
26- @ Option (names = { "-k" , "--api-key" }, description = "Mindee V2 API key." )
27- protected String apiKey ;
28-
2923 @ Option (names = { "-a" , "--alias" }, description = "Alias for the file" )
3024 protected String alias ;
3125
@@ -35,23 +29,6 @@ public abstract class BaseInferenceCommand implements Callable<Integer> {
3529 )
3630 private List <String > webhookIds ;
3731
38- /** Output format for the command. */
39- public enum OutputType {
40- summary ,
41- full ,
42- raw
43- }
44-
45- @ Option (
46- names = { "-o" , "--output" },
47- description = "Specify how to output the data.\n "
48- + "- summary: a basic summary (default)\n "
49- + "- full: detail extraction results, including options\n "
50- + "- raw: full JSON object" ,
51- defaultValue = "summary"
52- )
53- protected OutputType output ;
54-
5532 /**
5633 * @return The properly formatted webhook IDs.
5734 */
@@ -72,48 +49,12 @@ protected abstract CommonResponse executeRequest(
7249 LocalInputSource inputSource
7350 ) throws Exception ;
7451
75- /**
76- * Returns the summary (result-only) string for the given response.
77- * Override in each product command.
78- *
79- * @param response the product response
80- * @return the summary string
81- */
82- protected abstract String getSummary (CommonResponse response );
83-
84- /**
85- * Returns the full (inference + options + result) string for the given response.
86- * Defaults to the same as {@link #getSummary}; override for richer output.
87- *
88- * @param response the product response
89- * @return the full output string
90- */
91- protected String getFullOutput (CommonResponse response ) {
92- return getSummary (response );
93- }
94-
9552 @ Override
9653 public Integer call () throws Exception {
97- var client = new MindeeClient (apiKey != null ? apiKey : "" );
54+ var client = new MindeeClient (String . valueOf ( apiKey ) );
9855 var inputSource = new LocalInputSource (file );
9956 var response = executeRequest (client , inputSource );
10057 printOutput (response );
10158 return 0 ;
10259 }
103-
104- private void printOutput (CommonResponse response ) throws Exception {
105- switch (output ) {
106- case full :
107- System .out .println (getFullOutput (response ));
108- break ;
109- case raw :
110- var mapper = new ObjectMapper ().enable (SerializationFeature .INDENT_OUTPUT );
111- var jsonNode = mapper .readTree (response .getRawResponse ());
112- System .out .println (mapper .writeValueAsString (jsonNode ));
113- break ;
114- default :
115- System .out .println (getSummary (response ));
116- break ;
117- }
118- }
11960}
0 commit comments