Skip to content

Commit

Permalink
feat: add strict and no-strict options to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
RoryPTB committed Aug 9, 2024
1 parent 0865725 commit 0967b56
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ We can perform a total validation of the CAP XML file:
```bash
capvalidator validate <cap-file-directory>
```
By default this includes schema and signature validation.

To disable strict validation, that is, enforcement of a valid XML signature, we can use the `--no-strict` argument:
To manually enable/disable enforcement of a valid XML signature, we can use the `--strict` or `--no-strict` arguments respectively:

```bash
capvalidator validate <cap_file-directory> --no-strict
capvalidator validate --strict <cap_file-directory>
```

Or, alternatively, more refined validations:
```bash
capvalidator validate --no-strict <cap_file-directory>
```

Or, alternatively, for more refined validations we can use the `--type` argument:
```bash
capvalidator validate --type schema <cap-file-directory>
```
Expand Down
7 changes: 5 additions & 2 deletions src/capvalidator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ def cli():
@click.option('--type', 'validation_type',
type=click.Choice(['total', 'schema', 'signature']),
required=False, default='total')
@click.option('--strict/--no-strict', 'strict',
required=False, default=True,
help='Disable validation of the XML signature')
@click.argument('cap_xml', type=click.File(mode="rb", errors="ignore"))
def validate(ctx, cap_xml, validation_type) -> None:
def validate(ctx, cap_xml, validation_type, strict=True) -> None:
"""Validate a CAP alert"""

cap = cap_xml.read()

if validation_type == "total":
result = validate_xml(cap)
result = validate_xml(cap, strict=strict)
elif validation_type == "schema":
result = check_schema(cap)
elif validation_type == "signature":
Expand Down

0 comments on commit 0967b56

Please sign in to comment.