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

CDPCAM-48, CDPCAM-43: Custom output and links to docs. #23

Merged
merged 4 commits into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[settings]
profile=black
src_paths=cdpctl,tests
skip=scripts/update_issue_templates.py
12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ repos:
rev: 20.8b1
hooks:
- id: black
args: [--safe, --quiet, --target-version, py36]
args: [--safe, --quiet, --target-version, py36, --exclude, scripts/update_issue_templates.py]
- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
Expand All @@ -20,6 +20,7 @@ repos:
- id: check-json
exclude: ^.vscode/
- id: check-yaml
args: [--allow-multiple-documents]
- id: requirements-txt-fixer
- id: check-byte-order-marker
- id: check-case-conflict
Expand All @@ -32,10 +33,11 @@ repos:
rev: v2.7.0
hooks:
- id: validate_manifest
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.4
hooks:
- id: autopep8
# - repo: https://github.com/pre-commit/mirrors-autopep8
# rev: v1.5.4
# hooks:
# - id: autopep8
# args: ["--exclude scripts/update_issue_templates.py"]
- repo: https://github.com/PyCQA/isort
rev: 5.5.0
hooks:
Expand Down
30 changes: 27 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@
"validate",
"infra",
"--config_file",
"config.yaml"
]
"config.yml"
],
"justMyCode": false
},
{
"name": "cdpctl validate infra -f json",
"type": "python",
"request": "launch",
"module": "cdpctl",
"args": [
"validate",
"infra",
"--config_file",
"config.yml",
"-f",
"json"
],
"justMyCode": false
},
{
"name": "cdpctl provision infra",
Expand All @@ -32,7 +48,7 @@
"provision",
"infra",
"--config_file",
"config.yaml"
"config.yml"
]
},
{
Expand All @@ -44,6 +60,14 @@
"config",
"skeleton"
]
},
{
"name": "generate issue templates",
"type": "python",
"request": "launch",
"program": "scripts/update_issue_templates.py",
"console": "integratedTerminal"
}

]
}
2 changes: 2 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ rules:
document-start:
level: error
present: false
ignore: |
**/issue_templates.yml
empty-lines:
level: error
max: 1
Expand Down
32 changes: 29 additions & 3 deletions cdpctl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@
from cdpctl.command.config import render_skeleton
from cdpctl.command.validate import run_validation

SUPPORTED_OUTPUT_TYPES = ["text", "json"]


@click.group(invoke_without_command=True)
@click.option("-q", "--quiet", is_flag=True, default=False)
@click.option("--debug/--no-debug", default=False)
@click.option("-v", "--version", is_flag=True, default=False)
@click.pass_context
def _cli(ctx, debug=False, version=False) -> None:
def _cli(ctx, debug=False, version=False, quiet=False) -> None:
"""Run the cli."""
ctx.ensure_object(dict)
ctx.obj["DEBUG"] = debug
ctx.obj["QUIET"] = quiet
if version:
print_version()
if ctx.invoked_subcommand is None:
Expand All @@ -77,9 +81,31 @@ def _cli(ctx, debug=False, version=False) -> None:
help="The config file to use. Defaults to config.yml.",
type=click.Path(exists=False),
)
def validate(ctx, target: str, config_file) -> None: # pylint: disable=unused-argument
@click.option(
"-o",
"--output_file",
default="-",
help="The file to output the results to. Defaults to stdout.",
type=click.Path(exists=False),
)
@click.option(
"-f",
"--output_format",
default="text",
help="The format to output the results as.",
type=click.Choice(SUPPORTED_OUTPUT_TYPES, case_sensitive=False),
)
def validate(
ctx, target: str, config_file, output_file, output_format
) -> None: # pylint: disable=unused-argument
"""Run validation checks on provided section."""
run_validation(target=target, config_file=config_file, debug=ctx.obj["DEBUG"])
run_validation(
target=target,
config_file=config_file,
debug=ctx.obj["DEBUG"],
output_format=output_format,
output_file=output_file,
)


@click.group()
Expand Down
19 changes: 17 additions & 2 deletions cdpctl/command/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@
import cdpctl.validation as validation
from cdpctl import SUPPORTED_PLATFORMS
from cdpctl.utils import load_config
from cdpctl.validation import UnrecoverableValidationError, conftest
from cdpctl.validation import UnrecoverableValidationError, conftest, get_issues
from cdpctl.validation.aws_utils import validate_aws_config
from cdpctl.validation.renderer import get_renderer


def run_validation(target: str, config_file: str, debug: bool = False) -> None:
def run_validation(
target: str,
config_file: str,
debug: bool = False,
output_format: str = "text",
output_file: str = "-",
wonderslug marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
"""Run the validate command."""
click.echo(
f"Targeting {click.style(target, fg='blue')} section with config file "
Expand Down Expand Up @@ -113,3 +120,11 @@ def run_validation(target: str, config_file: str, debug: bool = False) -> None:
options.append("-s")

pytest.main(options)

renderer = get_renderer(output_format=output_format)
renderer.render(get_issues(), output_file)
if output_file != "-":
click.echo(
message=f"Results written to file {click.format_filename(output_file)}.",
err=True,
)
Loading