@@ -251,7 +251,7 @@ def validate_bids_cmd(
251251
252252
253253@validate .command (
254- name = "hed- string" ,
254+ name = "string" ,
255255 epilog = """
256256This command validates a HED annotation string against a specified HED schema
257257version. It can optionally process definitions and check for warnings in addition
@@ -260,25 +260,25 @@ def validate_bids_cmd(
260260\b
261261Examples:
262262 # Basic validation of a HED string
263- hedpy validate hed- string "Event, (Sensory-event, (Visual-presentation, (Computer-screen, Face)))" -sv 8.3.0
263+ hedpy validate string "Event, (Sensory-event, (Visual-presentation, (Computer-screen, Face)))" -sv 8.3.0
264264
265265 # Validate with definitions
266- hedpy validate hed- string "Event, Def/MyDef" -sv 8.4.0 -d "(Definition/MyDef, (Action, Move))"
266+ hedpy validate string "Event, Def/MyDef" -sv 8.4.0 -d "(Definition/MyDef, (Action, Move))"
267267
268268 # Validate with multiple schemas (base + library)
269- hedpy validate hed- string "Event, Action" -sv 8.3.0 -sv score_1.1.0
269+ hedpy validate string "Event, Action" -sv 8.3.0 -sv score_1.1.0
270270
271271 # Check for warnings as well as errors
272- hedpy validate hed- string "Event, Action/Button-press" -sv 8.4.0 --check-for-warnings
272+ hedpy validate string "Event, Action/Button-press" -sv 8.4.0 --check-for-warnings
273273
274274 # Save validation results to a file
275- hedpy validate hed- string "Event" -sv 8.4.0 -o validation_results.txt
275+ hedpy validate string "Event" -sv 8.4.0 -o validation_results.txt
276276
277277 # Output results in JSON format
278- hedpy validate hed- string "Event, Action" -sv 8.4.0 -f json
278+ hedpy validate string "Event, Action" -sv 8.4.0 -f json
279279
280280 # Verbose output with informational messages
281- hedpy validate hed- string "Event, (Action, Move)" -sv 8.4.0 --verbose
281+ hedpy validate string "Event, (Action, Move)" -sv 8.4.0 --verbose
282282""" ,
283283)
284284@click .argument ("hed_string" )
@@ -404,6 +404,140 @@ def validate_hed_string_cmd(
404404 ctx .exit (result if result is not None else 0 )
405405
406406
407+ @validate .command (
408+ name = "sidecar" ,
409+ epilog = """
410+ This command validates a BIDS JSON sidecar file against a specified HED schema
411+ version.
412+
413+ \b
414+ Examples:
415+ # Basic HED validation of a BIDS sidecar
416+ hedpy validate sidecar path/to/sidecar.json -sv 8.3.0
417+
418+ # Validate with multiple schemas (base + library)
419+ hedpy validate sidecar path/to/sidecar.json -sv 8.3.0 -sv score_1.1.0
420+
421+ # Check for warnings as well as errors
422+ hedpy validate sidecar path/to/sidecar.json -sv 8.4.0 --check-for-warnings
423+
424+ # Save validation results to a file
425+ hedpy validate sidecar path/to/sidecar.json -sv 8.4.0 -o validation_results.txt
426+ """ ,
427+ )
428+ @click .argument ("sidecar_file" , type = click .Path (exists = True ))
429+ # Validation options
430+ @optgroup .group ("Validation options" )
431+ @optgroup .option (
432+ "-sv" ,
433+ "--schema-version" ,
434+ required = True ,
435+ multiple = True ,
436+ metavar = "VERSION" ,
437+ help = "HED schema version(s) to validate against (e.g., '8.4.0'). Can be specified multiple times for multiple schemas (e.g., -sv lang_1.1.0 -sv score_2.1.0)" ,
438+ )
439+ @optgroup .option (
440+ "-w" ,
441+ "--check-for-warnings" ,
442+ is_flag = True ,
443+ help = "Check for warnings as well as errors" ,
444+ )
445+ # Output options
446+ @optgroup .group ("Output options" )
447+ @optgroup .option (
448+ "-f" ,
449+ "--format" ,
450+ type = click .Choice (["text" , "json" ]),
451+ default = "text" ,
452+ show_default = "text" ,
453+ help = "Output format for validation results (text: human-readable; json: structured format for programmatic use)" ,
454+ )
455+ @optgroup .option (
456+ "-o" ,
457+ "--output-file" ,
458+ type = click .Path (),
459+ default = "" ,
460+ metavar = METAVAR_FILE ,
461+ help = "Path for output file to hold validation results; if not specified, output to stdout" ,
462+ )
463+ # Logging options
464+ @optgroup .group ("Logging options" )
465+ @optgroup .option (
466+ "-l" ,
467+ "--log-level" ,
468+ type = click .Choice (["DEBUG" , "INFO" , "WARNING" , "ERROR" , "CRITICAL" ]),
469+ default = "WARNING" ,
470+ show_default = "WARNING" ,
471+ help = "Log level for diagnostic messages" ,
472+ )
473+ @optgroup .option (
474+ "-v" ,
475+ "--verbose" ,
476+ is_flag = True ,
477+ help = "Output informational messages (equivalent to --log-level INFO)" ,
478+ )
479+ @optgroup .option (
480+ "-lf" ,
481+ "--log-file" ,
482+ type = click .Path (),
483+ metavar = METAVAR_FILE ,
484+ help = "File path for saving log output; logs still go to stderr unless --log-quiet is also used" ,
485+ )
486+ @optgroup .option (
487+ "-lq" ,
488+ "--log-quiet" ,
489+ is_flag = True ,
490+ help = "Suppress log output to stderr; only applicable when --log-file is used (logs go only to file)" ,
491+ )
492+ @optgroup .option (
493+ "--no-log" ,
494+ is_flag = True ,
495+ help = "Disable all logging output" ,
496+ )
497+ @click .pass_context
498+ def validate_sidecar_cmd (
499+ ctx ,
500+ sidecar_file ,
501+ schema_version ,
502+ check_for_warnings ,
503+ format ,
504+ output_file ,
505+ log_level ,
506+ log_file ,
507+ log_quiet ,
508+ no_log ,
509+ verbose ,
510+ ):
511+ """Validate HED in a BIDS sidecar file.
512+
513+ SIDECAR_FILE: The path to the BIDS sidecar file to validate.
514+ """
515+ from hed .scripts .validate_hed_sidecar import main as validate_sidecar_main
516+
517+ args = [sidecar_file ]
518+ for version in schema_version :
519+ args .extend (["-sv" , version ])
520+ if check_for_warnings :
521+ args .append ("-w" )
522+ if format :
523+ args .extend (["-f" , format ])
524+ if output_file :
525+ args .extend (["-o" , output_file ])
526+ if log_level :
527+ args .extend (["-l" , log_level ])
528+ if log_file :
529+ args .extend (["-lf" , log_file ])
530+ if log_quiet :
531+ args .append ("-lq" )
532+ if no_log :
533+ args .append ("--no-log" )
534+ if verbose :
535+ args .append ("-v" )
536+
537+ result = validate_sidecar_main (args )
538+ ctx .exit (result if result is not None else 0 )
539+
540+
407541@schema .command (name = "validate" )
408542@click .argument ("schema_path" , type = click .Path (exists = True ), nargs = - 1 , required = True )
409543@click .option ("--add-all-extensions" , is_flag = True , help = "Always verify all versions of the same schema are equal" )
0 commit comments