Skip to content

Commit 8008d98

Browse files
✨ add support for V2 CLI (#200)
1 parent af96bbb commit 8008d98

23 files changed

Lines changed: 1509 additions & 29 deletions

.github/workflows/_publish-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v4
1616

17-
- name: Set up php ${{ matrix.php-version }}
17+
- name: Set up php 8.3
1818
uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: 8.3
@@ -30,7 +30,7 @@ jobs:
3030
cp -r ./docs/code_samples ./docs/_build/
3131
3232
- name: Deploy
33-
uses: peaceiris/actions-gh-pages@v3
33+
uses: peaceiris/actions-gh-pages@v4
3434
with:
3535
github_token: ${{ secrets.GITHUB_TOKEN }}
3636
publish_dir: ./docs/_build

.github/workflows/_static-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
tools: composer
2121

2222
- name: Cache dependencies
23-
uses: actions/cache@v3
23+
uses: actions/cache@v5
2424
with:
2525
path: ./vendor
2626
key: ${{ runner.os }}-${{ hashFiles('composer.json') }}

.github/workflows/_test-cli.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test Command Line Interface
2+
3+
on:
4+
workflow_call:
5+
workflow_dispatch:
6+
7+
env:
8+
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
9+
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
10+
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
11+
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
12+
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
13+
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
14+
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
15+
16+
jobs:
17+
test:
18+
name: Run CLI Tests
19+
timeout-minutes: 30
20+
strategy:
21+
max-parallel: 2
22+
matrix:
23+
php-version:
24+
- "8.1"
25+
- "8.5"
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: recursive
31+
32+
- name: Set up PHP ${{ matrix.php-version }}
33+
uses: shivammathur/setup-php@v2
34+
with:
35+
php-version: ${{ matrix.php-version }}
36+
- uses: ramsey/composer-install@v3
37+
38+
- name: Test V2 CLI
39+
shell: sh
40+
run: |
41+
./tests/test_v2_cli.sh ./tests/resources/file_types/pdf/blank_1.pdf
42+
43+
- name: Test V1 CLI
44+
shell: sh
45+
run: |
46+
./tests/test_v1_cli.sh ./tests/resources/file_types/pdf/blank_1.pdf
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint workflows
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
actionlint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Download actionlint
15+
id: get_actionlint
16+
run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
17+
shell: bash
18+
- name: Run actionlint
19+
run: ${{ steps.get_actionlint.outputs.executable }} -color
20+
shell: bash

.github/workflows/cron.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ jobs:
88
smoke-test:
99
uses: mindee/mindee-api-php/.github/workflows/_test-smoke.yml@main
1010
secrets: inherit
11+
test-cli:
12+
uses: mindee/mindee-api-php/.github/workflows/_test-cli.yml@main
13+
secrets: inherit

.github/workflows/pull-request.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ permissions:
88
pull-requests: read
99

1010
jobs:
11+
workflow-lint:
12+
uses: ./.github/workflows/_workflow_lint.yml
1113
static-analysis:
1214
uses: ./.github/workflows/_static-analysis.yml
15+
needs: workflow-lint
1316
static-dependency-checks:
1417
uses: ./.github/workflows/_static-dependency-checks.yml
1518
needs: static-analysis
@@ -25,3 +28,7 @@ jobs:
2528
uses: ./.github/workflows/_test-smoke.yml
2629
needs: test-units
2730
secrets: inherit
31+
test-cli:
32+
uses: ./.github/workflows/_test-cli.yml
33+
needs: test-units
34+
secrets: inherit

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Mindee PHP API Library Changelog
22

3+
34
## v3.0.0-rc1 - 2026-06-10
45
### Changes
56
* :recycle: move page count to attribute

CLI.md

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,105 @@
22

33
The CLI tool is provided mainly for quick tests and debugging.
44

5+
The CLI ships **two top-level groups**:
6+
7+
* V2 product subcommands at the root: `extraction`, `classification`,
8+
`crop`, `ocr`, `split`, plus `search-models`.
9+
* All V1 products live under a `v1` group (e.g. `mindee v1 invoice ...`).
10+
11+
For backward compatibility, invoking a V1 product name directly
12+
(`mindee invoice ...`, `mindee receipt ...`, …) is automatically
13+
dispatched to `mindee v1 <product> ...`.
14+
515
### General help
616

717
```shell
8-
./mindee generated --help
18+
./mindee --help
19+
./mindee v1 --help
20+
./mindee extraction --help
21+
./mindee search-models --help
922
```
1023

1124
> Note: Due to the limited-nature of most PHP CLI tools, the help sections aren't customized for each command.
1225
26+
## V1 commands
27+
1328
### Example parse command for Off-the-Shelf document
1429

1530
```shell
16-
./mindee invoice -k xxxxxxx /path/to/invoice.pdf
31+
./mindee v1 invoice -k xxxxxxx /path/to/invoice.pdf
1732
```
1833

34+
> Legacy `./mindee invoice -k xxxxxxx /path/to/invoice.pdf` still works.
35+
1936
### Works with environment variables
2037

2138
```shell
2239
export MINDEE_API_KEY=xxxxxx
23-
./mindee invoice /path/to/invoice.pdf
40+
./mindee v1 invoice /path/to/invoice.pdf
2441
```
2542

2643
### Example parse command for a generated document (docTI)
2744

2845
```shell
29-
./mindee generated -a pikachu -k xxxxxxx pokemon_card /path/to/card.jpg -A
46+
./mindee v1 generated -a pikachu -k xxxxxxx pokemon_card /path/to/card.jpg -A
3047
```
3148

3249

3350
### Example async parse command
3451

3552
```shell
36-
./mindee invoice-splitter path/to/the/invoice.pdf -A
53+
./mindee v1 invoice-splitter path/to/the/invoice.pdf -A
3754
```
3855

3956
> Note: the `-A` can be omitted on products which do not support synchronous mode.
4057
58+
### Full parsed output
59+
4160
```shell
42-
./mindee invoice-splitter path/to/the/invoice.pdf -A
61+
./mindee v1 invoice -k xxxxxxx /path/to/invoice.pdf -o raw
4362
```
4463

45-
### [DEPRECATED] Example parse command for a custom document (API Builder)
64+
## V2 commands
65+
66+
V2 inference commands share the same option set:
67+
68+
| Option | Short | Description |
69+
|--------|-------|-------------|
70+
| `--model-id` | `-m` | ID of the model to use (required). |
71+
| `--api-key` | `-k` | API key. Falls back to `MINDEE_V2_API_KEY`. |
72+
| `--alias` | `-a` | Optional alias for the file. |
73+
| `--output` | `-o` | `summary` (default), `full`, or `raw`. |
74+
75+
The `extraction` command adds:
76+
77+
| Option | Short | Description |
78+
|--------|-------|-------------|
79+
| `--rag` | `-g` | Enable Retrieval-Augmented Generation. |
80+
| `--raw-text` | `-r` | Extract the document's raw text. |
81+
| `--confidence` | `-c` | Return per-field confidence scores. |
82+
| `--polygon` | `-p` | Return per-field bounding polygons. |
83+
| `--text-context` | `-t` | Add text context to the API call. |
84+
85+
### Example V2 extraction call
4686

4787
```shell
48-
./mindee custom -a pikachu -k xxxxxxx pokemon_card /path/to/card.jpg
88+
export MINDEE_V2_API_KEY=xxxxxx
89+
./mindee extraction -m <model-id> /path/to/file.pdf
4990
```
5091

51-
### Full parsed output
92+
### Example V2 extraction with options and a JSON dump
93+
94+
```shell
95+
./mindee extraction -m <model-id> -k <api-key> -r -c -p -o full /path/to/file.pdf
96+
./mindee extraction -m <model-id> -o raw /path/to/file.pdf
97+
```
98+
99+
### Listing models
52100

53101
```shell
54-
./mindee invoice -k xxxxxxx /path/to/invoice.pdf -o raw
102+
./mindee search-models -k <api-key>
103+
./mindee search-models --name fin --model-type extraction -r
55104
```
56105

57106
### Running the script through php

bin/MindeeCliCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ class MindeeCliCommand extends Command
4949
*/
5050
public function __construct(array $documentList)
5151
{
52-
require __DIR__ . '/../src/version.php';
52+
require_once __DIR__ . '/../src/version.php';
5353
$this->documentList = $documentList;
5454

5555
$this->acceptableDocuments = [];
5656
foreach ($this->documentList as $documentName => $document) {
5757
$this->acceptableDocuments[] = $documentName;
5858
}
59-
parent::__construct('mindee');
59+
parent::__construct('v1');
6060
}
6161

6262
/**
@@ -66,9 +66,9 @@ protected function formatHelp(string $product = null): string
6666
{
6767
$helpCondensed = "";
6868
if (!$product) {
69-
$helpCondensed = "Mindee Command-Line interface.
69+
$helpCondensed = "Mindee V1 Command-Line interface.
7070
Usage:
71-
mindee [options] [--] <product> <method> <file_path_or_url>
71+
mindee v1 [options] [--] <product> <file_path_or_url>
7272
7373
Available products:";
7474
foreach ($this->documentList as $documentName => $document) {
@@ -92,8 +92,8 @@ protected function formatHelp(string $product = null): string
9292
protected function configure(): void
9393
{
9494
$this
95-
->setName('mindee')
96-
->setDescription('Mindee client.')
95+
->setName('v1')
96+
->setDescription('Mindee V1 product commands.')
9797
->addArgument(
9898
'product',
9999
InputArgument::REQUIRED,

0 commit comments

Comments
 (0)