Skip to content

Commit b7b0212

Browse files
committed
CLI and error messages
1 parent 2220e89 commit b7b0212

15 files changed

Lines changed: 71 additions & 50 deletions

‎src/main/java/com/mindee/MindeeException.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
*/
66
public class MindeeException extends RuntimeException {
77

8-
public MindeeException(String errorMessage, Throwable err) {
9-
super(errorMessage, err);
8+
public MindeeException(String message, Throwable cause) {
9+
super(message, cause);
1010
}
1111

12-
public MindeeException(String errorMessage) {
13-
super(errorMessage);
12+
public MindeeException(String message) {
13+
super(message);
1414
}
1515
}

‎src/main/java/com/mindee/v2/MindeeClient.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ private <TResponse extends CommonResponse> TResponse pollAndFetch(
280280
attempts++;
281281
}
282282

283-
ErrorResponse error = resp.getJob().getError();
284-
if (error != null) {
285-
throw new MindeeHttpExceptionV2(error.getStatus(), error.getDetail());
283+
ErrorResponse errorResponse = resp.getJob().getError();
284+
if (errorResponse != null) {
285+
throw new MindeeHttpExceptionV2(errorResponse);
286286
}
287287
throw new RuntimeException("Max retries exceeded (" + max + ").");
288288
}

‎src/main/java/com/mindee/v2/cli/BaseCommand.java‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
* Handles common options (path, model-id, api-key, alias, output) and output formatting.
1212
*/
1313
public abstract class BaseCommand implements Callable<Integer> {
14-
@CommandLine.Option(names = { "-k", "--api-key" }, description = "Mindee V2 API key.")
14+
@CommandLine.Option(
15+
names = { "-k", "--api-key" },
16+
description = "Mindee V2 API key.",
17+
defaultValue = ""
18+
)
1519
protected String apiKey;
1620

1721
/** Output format for the command. */
@@ -24,8 +28,8 @@ public enum OutputType {
2428
@CommandLine.Option(
2529
names = { "-o", "--output" },
2630
description = "Specify how to output the data.\n"
27-
+ "- summary: a basic summary (default)\n"
28-
+ "- full: detail extraction results, including options\n"
31+
+ "- summary: basic formatted response (default)\n"
32+
+ "- full: complete formatted response\n"
2933
+ "- raw: full JSON object",
3034
defaultValue = "summary"
3135
)
@@ -38,7 +42,7 @@ public enum OutputType {
3842
* @param response the response
3943
* @return the summary string
4044
*/
41-
protected abstract String getSummary(CommonResponse response);
45+
protected abstract String getSummaryOutput(CommonResponse response);
4246

4347
/**
4448
* Returns the full string for the given response.
@@ -62,7 +66,7 @@ protected void printOutput(CommonResponse response) throws Exception {
6266
System.out.println(mapper.writeValueAsString(jsonNode));
6367
break;
6468
default:
65-
System.out.println(getSummary(response));
69+
System.out.println(getSummaryOutput(response));
6670
break;
6771
}
6872
}

‎src/main/java/com/mindee/v2/cli/BaseInferenceCommand.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected abstract CommonResponse executeRequest(
5151

5252
@Override
5353
public Integer call() throws Exception {
54-
var client = new MindeeClient(String.valueOf(apiKey));
54+
var client = new MindeeClient(apiKey);
5555
var inputSource = new LocalInputSource(file);
5656
var response = executeRequest(client, inputSource);
5757
printOutput(response);

‎src/main/java/com/mindee/v2/cli/ClassificationCommand.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected CommonResponse executeRequest(
3131
}
3232

3333
@Override
34-
protected String getSummary(CommonResponse response) {
34+
protected String getSummaryOutput(CommonResponse response) {
3535
return ((ClassificationResponse) response).getInference().getResult().toString();
3636
}
3737

‎src/main/java/com/mindee/v2/cli/CropCommand.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected CommonResponse executeRequest(
2727
}
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((CropResponse) response).getInference().getResult().toString();
3232
}
3333

‎src/main/java/com/mindee/v2/cli/ExtractionCommand.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected CommonResponse executeRequest(
7777
}
7878

7979
@Override
80-
protected String getSummary(CommonResponse response) {
80+
protected String getSummaryOutput(CommonResponse response) {
8181
return ((ExtractionResponse) response).getInference().getResult().toString();
8282
}
8383

‎src/main/java/com/mindee/v2/cli/OcrCommand.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected CommonResponse executeRequest(
2727
}
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((OcrResponse) response).getInference().getResult().toString();
3232
}
3333

‎src/main/java/com/mindee/v2/cli/SearchModelsCommand.java‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,22 @@ public enum ModelType {
3939

4040
@Override
4141
public Integer call() throws Exception {
42-
var client = new MindeeClient(String.valueOf(apiKey));
42+
var client = new MindeeClient(apiKey);
4343
var response = client
4444
.search(
4545
ModelSearchResponse.class,
46-
ModelSearchParameters.builder().name(name).modelType(String.valueOf(modelType)).build()
46+
ModelSearchParameters
47+
.builder()
48+
.name(name)
49+
.modelType(modelType != null ? modelType.name() : null)
50+
.build()
4751
);
4852
printOutput(response);
4953
return 0;
5054
}
5155

5256
@Override
53-
protected String getSummary(CommonResponse response) {
57+
protected String getSummaryOutput(CommonResponse response) {
5458
return ((ModelSearchResponse) response).getModels().toString();
5559
}
5660

‎src/main/java/com/mindee/v2/cli/SearchRagDocumentsCommand.java‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class SearchRagDocumentsCommand extends BaseCommand {
2727
private String filename;
2828

2929
@Override
30-
protected String getSummary(CommonResponse response) {
30+
protected String getSummaryOutput(CommonResponse response) {
3131
return ((RagDocumentSearchResponse) response).getRagDocuments().toString();
3232
}
3333

@@ -38,11 +38,14 @@ protected String getFullOutput(CommonResponse response) {
3838

3939
@Override
4040
public Integer call() throws Exception {
41-
var client = new MindeeClient(String.valueOf(apiKey));
41+
var client = new MindeeClient(apiKey);
4242
var response = client
4343
.search(
4444
RagDocumentSearchResponse.class,
45-
RagDocumentSearchParameters.builder(modelId).filename(filename).build()
45+
RagDocumentSearchParameters
46+
.builder(modelId)
47+
.filename(filename != null ? filename : null)
48+
.build()
4649
);
4750
printOutput(response);
4851
return 0;

0 commit comments

Comments
 (0)