Skip to content

cli

CLI interface of dirschema (see dirschema --help).

run_dirschema

run_dirschema(
    schema: Path = _schema_arg,
    dir: Path = _dir_arg,
    conv: Tuple[str, str, str, str] = _conv_opt,
    local_basedir: Path = _local_basedir_opt,
    relative_prefix: str = _rel_prefix_opt,
    verbose: int = _verbose_opt,
) -> None

Run dirschema validation of a directory against a schema.

Performs validation according to schema and prints all unsatisfied constraints.

Source code in src/dirschema/cli.py
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
@app.command()
def run_dirschema(
    schema: Path = _schema_arg,
    dir: Path = _dir_arg,
    conv: Tuple[str, str, str, str] = _conv_opt,
    local_basedir: Path = _local_basedir_opt,
    relative_prefix: str = _rel_prefix_opt,
    verbose: int = _verbose_opt,
) -> None:
    """Run dirschema validation of a directory against a schema.

    Performs validation according to schema and prints all unsatisfied constraints.
    """
    logger.setLevel(log_level[verbose])
    local_basedir = local_basedir or schema.parent
    dsv = DSValidator(
        schema,
        MetaConvention.from_tuple(*conv),
        local_basedir=local_basedir,
        relative_prefix=relative_prefix,
    )
    if errors := dsv.validate(dir):
        logger.debug(f"Validation of '{dir}' failed")
        dsv.format_errors(errors, sys.stdout)
        raise typer.Exit(code=1)
    logger.debug(f"Validation of '{dir}' successful")