Skip to content

Commit f5d65ae

Browse files
committed
docs: add CLI reference and extractor docs for nexuslims extract command
Documents the `nexuslims extract` command in cli_reference.md and extractors.md, and corrects the help text in extract.py to accurately describe where output files are written (alongside the input file, not the NexusLIMS data directory, unless the file is under NX_INSTRUMENT_DATA_PATH).
1 parent b6a2dc1 commit f5d65ae

4 files changed

Lines changed: 222 additions & 6 deletions

File tree

docs/changes/96.doc.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add CLI reference and extractor documentation for the `nexuslims extract` command.

docs/user_guide/cli_reference.md

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ subcommands, flags, and `click.Path` arguments:
5454

5555
```text
5656
$ nexuslims <Tab>
57-
build-records completion config db instruments
57+
build-records completion config db extract instruments
5858
5959
$ nexuslims build-records --<Tab>
6060
--dry-run --from --help --to --verbose --version
@@ -92,6 +92,7 @@ Commands:
9292
completion Print shell completion setup instructions.
9393
config Manage NexusLIMS configuration files.
9494
db Manage NexusLIMS database.
95+
extract Extract metadata and/or generate a preview for a single file.
9596
instruments Manage NexusLIMS instruments.
9697
```
9798

@@ -400,6 +401,175 @@ See the {doc}`configuration guide <configuration>` Email Notifications section f
400401

401402
---
402403

404+
---
405+
406+
(extract-cli-ref)=
407+
## `nexuslims extract`
408+
409+
Extract metadata and/or generate a preview thumbnail for a single microscopy
410+
file. Useful for inspecting what NexusLIMS sees in a file without running the
411+
full record-building pipeline.
412+
413+
### Basic Usage
414+
415+
```bash
416+
nexuslims extract --help
417+
```
418+
419+
```text
420+
Usage: nexuslims extract [OPTIONS] FILE
421+
422+
Extract metadata and/or generate a preview for a single FILE.
423+
424+
Metadata is printed to stdout as JSON by default. Use --write to also
425+
persist it to the NexusLIMS data directory.
426+
427+
Examples:
428+
nexuslims extract image.dm4
429+
nexuslims extract --no-preview spectrum.msa
430+
nexuslims extract --no-metadata --preview-path /tmp/thumb.png image.tif
431+
nexuslims extract --write --overwrite image.dm4
432+
433+
Options:
434+
--no-preview Skip preview image generation.
435+
--no-metadata Skip metadata extraction (only generate preview).
436+
-p, --preview-path PATH Path to write the preview image. If omitted, the
437+
preview is written alongside the input file as
438+
'<filename>.thumb.png'.
439+
-w, --write Write metadata JSON alongside the input file as
440+
'<filename>.json'. If the file is under
441+
NX_INSTRUMENT_DATA_PATH, the JSON is written to the
442+
corresponding location under NX_DATA_PATH instead.
443+
By default, metadata is only printed to stdout.
444+
--overwrite Overwrite existing metadata JSON and preview files.
445+
-v, --verbose Enable verbose logging output.
446+
--help Show this message and exit.
447+
```
448+
449+
### Options
450+
451+
#### `FILE` (required argument)
452+
453+
Path to the microscopy file to extract. The file must exist.
454+
455+
#### `--no-preview`
456+
457+
Skip thumbnail generation. Only metadata extraction is performed and the JSON
458+
is printed to stdout.
459+
460+
**Example:**
461+
```bash
462+
nexuslims extract --no-preview /data/spectrum.msa
463+
```
464+
465+
#### `--no-metadata`
466+
467+
Skip metadata extraction. Only the preview image is generated. Cannot be used
468+
together with `--no-preview`.
469+
470+
**Example:**
471+
```bash
472+
nexuslims extract --no-metadata /data/image.dm4
473+
```
474+
475+
#### `-p, --preview-path PATH`
476+
477+
Write the preview image to the given path instead of the default location. The
478+
parent directory is created automatically. If omitted, the preview is written
479+
alongside the input file as `<filename>.thumb.png`.
480+
481+
**Example:**
482+
```bash
483+
nexuslims extract -p /tmp/thumb.png /data/image.dm4
484+
```
485+
486+
#### `-w, --write`
487+
488+
Persist the extracted metadata JSON to disk. By default, metadata is only
489+
printed to stdout. The output location depends on the file's path:
490+
491+
- If the file is **outside** `NX_INSTRUMENT_DATA_PATH` (typical for ad-hoc
492+
use), the JSON is written alongside the input file as `<filename>.json`.
493+
- If the file is **under** `NX_INSTRUMENT_DATA_PATH`, the JSON is written to
494+
the corresponding mirror path under `NX_DATA_PATH` (the same behavior as
495+
the full record-building pipeline).
496+
497+
**Example:**
498+
```bash
499+
nexuslims extract --write /data/image.dm4
500+
```
501+
502+
#### `--overwrite`
503+
504+
Allow overwriting an existing metadata JSON or preview file. By default, the
505+
command skips writing if the output file already exists.
506+
507+
**Example:**
508+
```bash
509+
nexuslims extract --write --overwrite /data/image.dm4
510+
```
511+
512+
#### `-v, --verbose`
513+
514+
Enable `DEBUG`-level logging. By default only `WARNING` and above are shown.
515+
516+
**Example:**
517+
```bash
518+
nexuslims extract -v /data/image.dm4
519+
```
520+
521+
### Exit Codes
522+
523+
- **0**: Success
524+
- **1**: No extractor found for the given file format, or both `--no-metadata`
525+
and `--no-preview` were specified together
526+
527+
### Examples
528+
529+
#### Inspect metadata for a DM4 file
530+
531+
```bash
532+
nexuslims extract /data/sample.dm4
533+
```
534+
535+
Prints the full extracted metadata as pretty-printed JSON to stdout.
536+
537+
#### Inspect metadata without generating a preview
538+
539+
```bash
540+
nexuslims extract --no-preview /data/sample.dm4
541+
```
542+
543+
#### Generate a preview thumbnail at a specific path
544+
545+
```bash
546+
nexuslims extract --no-metadata --preview-path /tmp/thumb.png /data/sample.dm4
547+
```
548+
549+
#### Extract and persist both metadata and preview
550+
551+
```bash
552+
nexuslims extract --write /data/sample.dm4
553+
```
554+
555+
Writes the JSON sidecar alongside the input file (as `sample.dm4.json`) and
556+
prints the metadata to stdout. If `sample.dm4` is under `NX_INSTRUMENT_DATA_PATH`,
557+
the JSON is instead written to the corresponding path under `NX_DATA_PATH`.
558+
559+
#### Re-extract and overwrite existing outputs
560+
561+
```bash
562+
nexuslims extract --write --overwrite /data/sample.dm4
563+
```
564+
565+
#### Pipe metadata into jq for filtering
566+
567+
```bash
568+
nexuslims extract /data/sample.dm4 | jq '.nx_meta.DatasetType'
569+
```
570+
571+
---
572+
403573
## `nexuslims instruments manage`
404574

405575
Terminal user interface (TUI) for managing the NexusLIMS instruments database.

docs/user_guide/extractors.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,49 @@ Use the `extensions` dictionary when:
809809

810810
See {ref}`Helper Functions <metadata-helper-functions>` for the `add_to_extensions()` helper function and {doc}`../dev_guide/writing_extractor_plugins` for complete guidance on using extensions in your own extractors.
811811

812+
(extract-cli)=
813+
## Command-Line Extraction
814+
815+
The `nexuslims extract` command lets you extract metadata and generate preview
816+
thumbnails for individual files directly from the terminal, without writing any
817+
Python code and without a full NexusLIMS deployment.
818+
819+
### Quick reference
820+
821+
```bash
822+
# Print extracted metadata as JSON
823+
nexuslims extract /path/to/file.dm4
824+
825+
# Extract metadata only (skip preview generation)
826+
nexuslims extract --no-preview /path/to/file.msa
827+
828+
# Generate a preview thumbnail only, saved to a specific path
829+
nexuslims extract --no-metadata --preview-path /tmp/thumb.png /path/to/file.tif
830+
831+
# Also write the JSON sidecar to the NexusLIMS data directory
832+
nexuslims extract --write /path/to/file.dm4
833+
834+
# Overwrite existing outputs
835+
nexuslims extract --write --overwrite /path/to/file.dm4
836+
837+
# Pipe metadata into jq
838+
nexuslims extract /path/to/file.dm4 | jq '.nx_meta.DatasetType'
839+
```
840+
841+
By default:
842+
843+
- Metadata is printed to stdout as pretty-printed JSON.
844+
- A preview thumbnail is generated and written alongside the input file as
845+
`<filename>.thumb.png`; its path is printed to stderr.
846+
- The metadata JSON is **not** written to disk unless `--write` / `-w` is
847+
given. With `--write`, the JSON is written alongside the input file as
848+
`<filename>.json` (or to the corresponding path under `NX_DATA_PATH` if the
849+
file is under `NX_INSTRUMENT_DATA_PATH`).
850+
- Use `-p / --preview-path` to control where the thumbnail is saved.
851+
852+
For full option documentation see {ref}`nexuslims extract <extract-cli-ref>` in
853+
the CLI reference.
854+
812855
(standalone-extractor-usage)=
813856
## Standalone Library Usage
814857

nexusLIMS/cli/extract.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
# Save preview to a specific path
1919
nexuslims extract --preview-path /tmp/preview.png /path/to/file.dm4
2020
21-
# Write metadata JSON to disk (mirrors normal record-building behavior)
21+
# Write metadata JSON alongside the file (or to NX_DATA_PATH if the file
22+
# is under NX_INSTRUMENT_DATA_PATH)
2223
nexuslims extract --write /path/to/file.dm4
2324
"""
2425

@@ -55,9 +56,8 @@
5556
type=click.Path(dir_okay=False, path_type=Path),
5657
default=None,
5758
help=(
58-
"Path to write the preview image. If omitted, prints the path of the "
59-
"generated preview (written alongside the file in the NexusLIMS data "
60-
"directory structure)."
59+
"Path to write the preview image. If omitted, the preview is written "
60+
"alongside the input file as '<filename>.thumb.png'."
6161
),
6262
)
6363
@click.option(
@@ -66,7 +66,9 @@
6666
is_flag=True,
6767
default=False,
6868
help=(
69-
"Write metadata JSON to disk (in the NexusLIMS data directory structure). "
69+
"Write metadata JSON to disk alongside the input file as '<filename>.json'. "
70+
"If the file is under NX_INSTRUMENT_DATA_PATH, the JSON is written to the "
71+
"corresponding location under NX_DATA_PATH instead. "
7072
"By default, metadata is only printed to stdout."
7173
),
7274
)

0 commit comments

Comments
 (0)