Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(anta.cli): Make CSV output file option mandatory #1052

Merged
merged 3 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ repos:
- --allow-past-years
- --fuzzy-match-generates-todo
- --comment-style
- '<!--| ~| -->'
- "<!--| ~| -->"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.6
hooks:
- id: ruff
name: Run Ruff linter
args: [ --fix ]
- id: ruff-format
name: Run Ruff formatter
- id: ruff
name: Run Ruff linter
args: [--fix]
- id: ruff-format
name: Run Ruff formatter

- repo: https://github.com/pycqa/pylint
rev: "v3.3.4"
Expand All @@ -62,9 +62,9 @@ repos:
description: This hook runs pylint.
types: [python]
args:
- -rn # Only display messages
- -sn # Don't display the score
- --rcfile=pyproject.toml # Link to config file
- -rn # Only display messages
- -sn # Don't display the score
- --rcfile=pyproject.toml # Link to config file
additional_dependencies:
- anta[cli]
- types-PyYAML
Expand Down Expand Up @@ -123,5 +123,14 @@ repos:
pass_filenames: false
additional_dependencies:
- anta[cli]
# TODO: next can go once we have it added to anta properly
- numpydoc
- id: doc-snippets
name: Generate doc snippets
entry: >-
sh -c "docs/scripts/generate_doc_snippets.py"
language: python
types: [python]
files: anta/cli/
verbose: true
pass_filenames: false
additional_dependencies:
- anta[cli]
5 changes: 3 additions & 2 deletions anta/cli/nrfu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ def parse_args(self, ctx: click.Context, args: list[str]) -> list[str]:
if "--help" not in args:
raise

# remove the required params so that help can display
# Fake presence of the required params so that help can display
for param in self.params:
param.required = False
if param.required:
param.value_is_missing = lambda value: False # type: ignore[method-assign] # noqa: ARG005

return super().parse_args(ctx, args)

Expand Down
9 changes: 6 additions & 3 deletions anta/cli/nrfu/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ def table(ctx: click.Context, group_by: Literal["device", "test"] | None) -> Non
help="Path to save report as a JSON file",
)
def json(ctx: click.Context, output: pathlib.Path | None) -> None:
"""ANTA command to check network state with JSON results."""
"""ANTA command to check network state with JSON results.

If no `--output` is specified, the output is printed to stdout.
"""
run_tests(ctx)
print_json(ctx, output=output)
exit_with_code(ctx)
Expand All @@ -72,11 +75,11 @@ def text(ctx: click.Context) -> None:
path_type=pathlib.Path,
),
show_envvar=True,
required=False,
required=True,
help="Path to save report as a CSV file",
)
def csv(ctx: click.Context, csv_output: pathlib.Path) -> None:
"""ANTA command to check network states with CSV result."""
"""ANTA command to check network state with CSV report."""
run_tests(ctx)
save_to_csv(ctx, csv_file=csv_output)
exit_with_code(ctx)
Expand Down
58 changes: 6 additions & 52 deletions docs/cli/nrfu.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ The `text` subcommand provides a straightforward text report for each test execu
### Command overview

```bash
Usage: anta nrfu text [OPTIONS]

ANTA command to check network states with text result.

Options:
--help Show this message and exit.
--8<-- "anta_nrfu_text_help.txt"
```

### Example
Expand All @@ -71,13 +66,7 @@ The `table` command under the `anta nrfu` namespace offers a clear and organized
### Command overview

```bash
Usage: anta nrfu table [OPTIONS]

ANTA command to check network states with table result.

Options:
--group-by [device|test] Group result by test or device.
--help Show this message and exit.
--8<-- "anta_nrfu_table_help.txt"
```

The `--group-by` option show a summarized view of the test results per host or per test.
Expand Down Expand Up @@ -125,15 +114,7 @@ The JSON rendering command in NRFU testing will generate an output of all test r
### Command overview

```bash
anta nrfu json --help
Usage: anta nrfu json [OPTIONS]

ANTA command to check network state with JSON result.

Options:
-o, --output FILE Path to save report as a JSON file [env var:
ANTA_NRFU_JSON_OUTPUT]
--help Show this message and exit.
--8<-- "anta_nrfu_json_help.txt"
```

The `--output` option allows you to save the JSON report as a file. If specified, no output will be displayed in the terminal. This is useful for further processing or integration with other tools.
Expand All @@ -153,15 +134,7 @@ The `csv` command in NRFU testing is useful for generating a CSV file with all t
### Command overview

```bash
anta nrfu csv --help
Usage: anta nrfu csv [OPTIONS]

ANTA command to check network states with CSV result.

Options:
--csv-output FILE Path to save report as a CSV file [env var:
ANTA_NRFU_CSV_CSV_OUTPUT]
--help Show this message and exit.
--8<-- "anta_nrfu_csv_help.txt"
```

### Example
Expand All @@ -175,16 +148,7 @@ The `md-report` command in NRFU testing generates a comprehensive Markdown repor
### Command overview

```bash
anta nrfu md-report --help

Usage: anta nrfu md-report [OPTIONS]

ANTA command to check network state with Markdown report.

Options:
--md-output FILE Path to save the report as a Markdown file [env var:
ANTA_NRFU_MD_REPORT_MD_OUTPUT; required]
--help Show this message and exit.
--8<-- "anta_nrfu_mdreport_help.txt"
```

### Example
Expand All @@ -198,17 +162,7 @@ ANTA offers a CLI option for creating custom reports. This leverages the Jinja2
### Command overview

```bash
anta nrfu tpl-report --help
Usage: anta nrfu tpl-report [OPTIONS]

ANTA command to check network state with templated report

Options:
-tpl, --template FILE Path to the template to use for the report [env var:
ANTA_NRFU_TPL_REPORT_TEMPLATE; required]
-o, --output FILE Path to save report as a file [env var:
ANTA_NRFU_TPL_REPORT_OUTPUT]
--help Show this message and exit.
--8<-- "anta_nrfu_tplreport_help.txt"
```

The `--template` option is used to specify the Jinja2 template file for generating the custom report.
Expand Down
6 changes: 4 additions & 2 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ This entrypoint has multiple options to manage test coverage and reporting.
--8<-- "anta_help.txt"
```

To run the NRFU, you need to select an output format amongst [`csv`, `json`, `md-report`, `table`, `text`, `tpl-report`].

For a first usage, `table` is recommended. By default all test results for all devices are rendered but it can be changed to a report per test case or per host

```bash
--8<-- "anta_nrfu_help.txt"
```

To run the NRFU, you need to select an output format amongst ["json", "table", "text", "tpl-report"]. For a first usage, `table` is recommended. By default all test results for all devices are rendered but it can be changed to a report per test case or per host

!!! Note
The following examples shows how to pass all the CLI options.

Expand Down
100 changes: 100 additions & 0 deletions docs/imgs/anta_debug_help.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading