From be1bbc3e5a7ad0b4ed4c83046d023bc08eb87f44 Mon Sep 17 00:00:00 2001 From: Thibaud Colas Date: Thu, 14 May 2020 21:54:26 +0100 Subject: [PATCH] Add `--print-config` CLI flag to print the configuration for the given file --- CHANGELOG.md | 4 ++++ README.md | 8 ++++++++ curlylint/cli.py | 7 +++++++ curlylint/config.py | 4 ++++ docs/README.md | 1 - 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a2a013..b6591e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## Unreleased +### Added + +- Add `--print-config` CLI flag to print the configuration for the given file. + ## [v0.9.0](https://github.com/thibaudcolas/curlylint/releases/tag/v0.9.0) 2020-05-14 ### Added diff --git a/README.md b/README.md index a007fce..6d15aa6 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,14 @@ Don’t lint, check for syntax errors and exit. curlylint --parse-only template-directory/ ``` +#### `--print-config` + +Print the configuration for the given file, and exit. + +```sh +curlylint --print-config some-file.html +``` + #### `--rule` Specify rules, with the syntax `--rule 'code: {"json": "value"}'`. Can be provided multiple times to configure multiple rules. diff --git a/curlylint/cli.py b/curlylint/cli.py index 2c679b6..1080076 100644 --- a/curlylint/cli.py +++ b/curlylint/cli.py @@ -63,6 +63,12 @@ def path_empty( is_flag=True, help="Don’t lint, check for syntax errors and exit.", ) +@click.option( + "--print-config", + is_flag=True, + help="Print the configuration for the given file.", + is_eager=True, +) @click.option( "-f", "--format", @@ -148,6 +154,7 @@ def main( verbose: bool, quiet: bool, parse_only: bool, + print_config: bool, config: Optional[str], format: str, stdin_filepath: str, diff --git a/curlylint/config.py b/curlylint/config.py index 302367b..ac068d4 100644 --- a/curlylint/config.py +++ b/curlylint/config.py @@ -80,6 +80,10 @@ def read_pyproject_toml( if not config: return None + if ctx.params.get("print_config", False): + print(toml.dumps({"tool": {"curlylint": config}})) + ctx.exit(0) + if ctx.default_map is None: ctx.default_map = {} ctx.default_map.update(config) # type: ignore # bad types in .pyi diff --git a/docs/README.md b/docs/README.md index 7b8b8d6..dd249a4 100644 --- a/docs/README.md +++ b/docs/README.md @@ -45,7 +45,6 @@ Most of curlylint’s CLI is already based on that of black: include/excludes, c - Support using a file with ignore paths. - Disable colored output. - Cache results / only check changed files. -- Print config for the given file. ## Linting ideas