11#!/usr/bin/env node
22import yargs , { type Argv , type CommandModule , type Options } from 'yargs'
3- import { loadSpectrumFromURL , loadSpectrumFromFilePath } from './prase-spectra'
3+ import { loadSpectrumFromURL , loadSpectrumFromFilePath } from './parse/ prase-spectra'
44import { generateSpectrumFromPublicationString } from './publication-string'
55import { parsePredictionCommand } from './prediction/parsePredictionCommand'
66import { hideBin } from 'yargs/helpers'
@@ -14,18 +14,14 @@ Commands:
1414 predict Predict spectrum from Mol
1515
1616Options for 'parse-spectra' command:
17- -u, --url File URL
18- -p, --path Directory path
19- -s, --capture-snapshot Capture snapshot
17+ -u, --url File URL
18+ -dir, --dir-path Directory path
19+ -s, --capture-snapshot Capture snapshot
20+ -p, --auto-processing Automatic processing of spectrum (FID → FT spectra).
21+ -d, --auto-detection Enable ranges and zones automatic detection.
2022
2123Arguments for 'parse-publication-string' command:
2224 publicationString Publication string
23-
24- Options for 'parse-spectra' command:
25- -u, --url File URL
26- -p, --path Directory path
27- -s, --capture-snapshot Capture snapshot
28-
2925
3026Options for 'predict' command:
3127 -ps,--peakShape Peak shape algorithm (default: "lorentzian") choices: ["gaussian", "lorentzian"]
@@ -46,16 +42,43 @@ Options for 'predict' command:
4642
4743Examples:
4844 nmr-cli parse-spectra -u file-url -s // Process spectra files from a URL and capture an image for the spectra
49- nmr-cli parse-spectra -p directory-path -s // process a spectra files from a directory and capture an image for the spectra
45+ nmr-cli parse-spectra -dir directory-path -s // process a spectra files from a directory and capture an image for the spectra
5046 nmr-cli parse-spectra -u file-url // Process spectra files from a URL
51- nmr-cli parse-spectra -p directory-path // Process spectra files from a directory
47+ nmr-cli parse-spectra -dir directory-path // Process spectra files from a directory
5248 nmr-cli parse-publication-string "your publication string"
5349`
5450
55- interface FileOptionsArgs {
56- u ? : string
57- p ? : string
58- s ? : boolean
51+ export interface FileOptionsArgs {
52+ /**
53+ * -u, --url
54+ * File URL to load remote spectra or data.
55+ */
56+ u ? : string ;
57+
58+ /**
59+ * -dir, --dir-path
60+ * Local directory path for file input or output.
61+ */
62+ dir ? : string ;
63+
64+ /**
65+ * -s, --capture-snapshot
66+ * Capture a visual snapshot of the current state or spectrum.
67+ */
68+ s ? : boolean ;
69+
70+ /**
71+ * -p, --auto-processing
72+ * Automatically process spectrum from FID to FT spectra.
73+ * Mandatory when automatic detection (`--auto-detection`) is enabled.
74+ */
75+ p ? : boolean ;
76+
77+ /**
78+ * -d, --auto-detection
79+ * Perform automatic ranges and zones detection.
80+ */
81+ d ? : boolean ;
5982}
6083
6184// Define options for parsing a spectra file
@@ -66,8 +89,8 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
6689 type : 'string' ,
6790 nargs : 1 ,
6891 } ,
69- p : {
70- alias : 'path' ,
92+ dir : {
93+ alias : 'dir- path' ,
7194 describe : 'Directory path' ,
7295 type : 'string' ,
7396 nargs : 1 ,
@@ -77,6 +100,16 @@ const fileOptions: { [key in keyof FileOptionsArgs]: Options } = {
77100 describe : 'Capture snapshot' ,
78101 type : 'boolean' ,
79102 } ,
103+ p : {
104+ alias : 'auto-processing' ,
105+ describe : 'Auto processing' ,
106+ type : 'boolean' ,
107+ } ,
108+ d : {
109+ alias : 'auto-detection' ,
110+ describe : 'Ranges and zones auto detection' ,
111+ type : 'boolean' ,
112+ } ,
80113} as const
81114
82115const parseFileCommand : CommandModule < { } , FileOptionsArgs > = {
@@ -85,21 +118,25 @@ const parseFileCommand: CommandModule<{}, FileOptionsArgs> = {
85118 builder : yargs => {
86119 return yargs
87120 . options ( fileOptions )
88- . conflicts ( 'u' , 'p ' ) as Argv < FileOptionsArgs >
121+ . conflicts ( 'u' , 'dir ' ) as Argv < FileOptionsArgs >
89122 } ,
90123 handler : argv => {
124+
125+ const { u, dir } = argv ;
91126 // Handle parsing the spectra file logic based on argv options
92- if ( argv ?. u ) {
93- loadSpectrumFromURL ( argv . u , argv . s ) . then ( result => {
127+ if ( u ) {
128+ loadSpectrumFromURL ( { u, ... argv } ) . then ( result => {
94129 console . log ( JSON . stringify ( result ) )
95130 } )
96131 }
97132
98- if ( argv ?. p ) {
99- loadSpectrumFromFilePath ( argv . p , argv . s ) . then ( result => {
133+
134+ if ( dir ) {
135+ loadSpectrumFromFilePath ( { dir, ...argv } ) . then ( result => {
100136 console . log ( JSON . stringify ( result ) )
101137 } )
102138 }
139+
103140 } ,
104141}
105142
0 commit comments