@@ -186,6 +186,11 @@ def validate():
186186 is_flag = True ,
187187 help = "Suppress log output to stderr; only applicable when --log-file is used (logs go only to file)" ,
188188)
189+ @optgroup .option (
190+ "--no-log" ,
191+ is_flag = True ,
192+ help = "Disable all logging output" ,
193+ )
189194def validate_bids_cmd (
190195 data_path ,
191196 error_limit ,
@@ -194,6 +199,7 @@ def validate_bids_cmd(
194199 log_level ,
195200 log_file ,
196201 log_quiet ,
202+ no_log ,
197203 output_file ,
198204 print_output ,
199205 suffixes ,
@@ -221,6 +227,8 @@ def validate_bids_cmd(
221227 args .extend (["-lf" , log_file ])
222228 if log_quiet :
223229 args .append ("-lq" )
230+ if no_log :
231+ args .append ("--no-log" )
224232 if output_file :
225233 args .extend (["-o" , output_file ])
226234 if print_output :
@@ -239,6 +247,157 @@ def validate_bids_cmd(
239247 validate_bids_main (args )
240248
241249
250+ @validate .command (
251+ name = "hed-string" ,
252+ epilog = """
253+ This command validates a HED annotation string against a specified HED schema
254+ version. It can optionally process definitions and check for warnings in addition
255+ to errors. Multiple schema versions can be specified for validation with library schemas.
256+
257+ \b
258+ Examples:
259+ # Basic validation of a HED string
260+ hedpy validate hed-string "Event, (Sensory-event, (Visual-presentation, (Computer-screen, Face)))" -sv 8.3.0
261+
262+ # Validate with definitions
263+ hedpy validate hed-string "Event, Def/MyDef" -sv 8.4.0 -d "(Definition/MyDef, (Action, Move))"
264+
265+ # Validate with multiple schemas (base + library)
266+ hedpy validate hed-string "Event, Action" -sv 8.3.0 -sv score_1.1.0
267+
268+ # Check for warnings as well as errors
269+ hedpy validate hed-string "Event, Action/Button-press" -sv 8.4.0 --check-for-warnings
270+
271+ # Save validation results to a file
272+ hedpy validate hed-string "Event" -sv 8.4.0 -o validation_results.txt
273+
274+ # Output results in JSON format
275+ hedpy validate hed-string "Event, Action" -sv 8.4.0 -f json
276+
277+ # Verbose output with informational messages
278+ hedpy validate hed-string "Event, (Action, Move)" -sv 8.4.0 --verbose
279+ """ ,
280+ )
281+ @click .argument ("hed_string" )
282+ # Validation options
283+ @optgroup .group ("Validation options" )
284+ @optgroup .option (
285+ "-sv" ,
286+ "--schema-version" ,
287+ required = True ,
288+ multiple = True ,
289+ metavar = "VERSION" ,
290+ help = "HED schema version(s) to validate against (e.g., '8.3.0'). Can be specified multiple times for multiple schemas (e.g., -sv 8.3.0 -sv score_1.1.0)" ,
291+ )
292+ @optgroup .option (
293+ "-d" ,
294+ "--definitions" ,
295+ default = "" ,
296+ metavar = METAVAR_STRING ,
297+ help = "A string containing relevant HED definitions to use during validation (e.g., '(Definition/MyDef, (Action, Move))')" ,
298+ )
299+ @optgroup .option (
300+ "-w" ,
301+ "--check-for-warnings" ,
302+ is_flag = True ,
303+ help = "Check for warnings as well as errors" ,
304+ )
305+ # Output options
306+ @optgroup .group ("Output options" )
307+ @optgroup .option (
308+ "-f" ,
309+ "--format" ,
310+ type = click .Choice (["text" , "json" ]),
311+ default = "text" ,
312+ show_default = "text" ,
313+ help = "Output format for validation results (text: human-readable; json: structured format for programmatic use)" ,
314+ )
315+ @optgroup .option (
316+ "-o" ,
317+ "--output-file" ,
318+ type = click .Path (),
319+ default = "" ,
320+ metavar = METAVAR_FILE ,
321+ help = "Path for output file to hold validation results; if not specified, output to stdout" ,
322+ )
323+ # Logging options
324+ @optgroup .group ("Logging options" )
325+ @optgroup .option (
326+ "-l" ,
327+ "--log-level" ,
328+ type = click .Choice (["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ]),
329+ default = "WARNING" ,
330+ show_default = "WARNING" ,
331+ help = "Log level for diagnostic messages" ,
332+ )
333+ @optgroup .option (
334+ "-v" ,
335+ "--verbose" ,
336+ is_flag = True ,
337+ help = "Output informational messages (equivalent to --log-level INFO)" ,
338+ )
339+ @optgroup .option (
340+ "-lf" ,
341+ "--log-file" ,
342+ type = click .Path (),
343+ metavar = METAVAR_FILE ,
344+ help = "File path for saving log output; logs still go to stderr unless --log-quiet is also used" ,
345+ )
346+ @optgroup .option (
347+ "-lq" ,
348+ "--log-quiet" ,
349+ is_flag = True ,
350+ help = "Suppress log output to stderr; only applicable when --log-file is used (logs go only to file)" ,
351+ )
352+ @optgroup .option (
353+ "--no-log" ,
354+ is_flag = True ,
355+ help = "Disable all logging output" ,
356+ )
357+ def validate_hed_string_cmd (
358+ hed_string ,
359+ schema_version ,
360+ definitions ,
361+ check_for_warnings ,
362+ format ,
363+ output_file ,
364+ log_level ,
365+ log_file ,
366+ log_quiet ,
367+ no_log ,
368+ verbose ,
369+ ):
370+ """Validate a HED annotation string.
371+
372+ HED_STRING: The HED annotation string to validate (use quotes for strings with spaces or special characters).
373+ """
374+ from hed .scripts .validate_hed_string import main as validate_string_main
375+
376+ args = [hed_string ]
377+ for version in schema_version :
378+ args .extend (["-sv" , version ])
379+ if definitions :
380+ args .extend (["-d" , definitions ])
381+ if check_for_warnings :
382+ args .append ("-w" )
383+ if format :
384+ args .extend (["-f" , format ])
385+ if output_file :
386+ args .extend (["-o" , output_file ])
387+ if log_level :
388+ args .extend (["-l" , log_level ])
389+ if log_file :
390+ args .extend (["-lf" , log_file ])
391+ if log_quiet :
392+ args .append ("-lq" )
393+ if no_log :
394+ args .append ("--no-log" )
395+ if verbose :
396+ args .append ("-v" )
397+
398+ validate_string_main (args )
399+
400+
242401@schema .command (name = "validate" )
243402@click .argument ("schema_path" , type = click .Path (exists = True ), nargs = - 1 , required = True )
244403@click .option ("--add-all-extensions" , is_flag = True , help = "Always verify all versions of the same schema are equal" )
0 commit comments