From 481ec109bf64773991f6a86c3973151662500469 Mon Sep 17 00:00:00 2001 From: Lemonyte <49930425+lemonyte@users.noreply.github.com> Date: Wed, 12 Jul 2023 07:07:37 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Support=20single=20files=20via=20CL?= =?UTF-8?q?I=20(#86)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Marcelo Trylesinski --- README.md | 4 ++-- bump_pydantic/main.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fca6d68..2ddcfe3 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ bump-pydantic --help To check the diff before applying the changes, you can run: ```bash -bump-pydantic --diff +bump-pydantic --diff ``` ### Apply changes @@ -63,7 +63,7 @@ bump-pydantic --diff To apply the changes, you can run: ```bash -bump-pydantic +bump-pydantic ``` ## Rules diff --git a/bump_pydantic/main.py b/bump_pydantic/main.py index fdc3abd..32f9389 100644 --- a/bump_pydantic/main.py +++ b/bump_pydantic/main.py @@ -42,7 +42,7 @@ def version_callback(value: bool): @app.callback() def main( - package: Path = Argument(..., exists=True, dir_okay=True, allow_dash=False), + path: Path = Argument(..., exists=True, dir_okay=True, allow_dash=False), disable: List[Rule] = Option(default=[], help="Disable a rule."), log_file: Path = Option("log.txt", help="Log errors to this file."), version: bool = Option( @@ -57,8 +57,14 @@ def main( # NOTE: LIBCST_PARSER_TYPE=native is required according to https://github.com/Instagram/LibCST/issues/487. os.environ["LIBCST_PARSER_TYPE"] = "native" - files_str = list(package.glob("**/*.py")) - files = [str(file.relative_to(".")) for file in files_str] + if os.path.isfile(path): + package = path.parent + files = [str(path.relative_to("."))] + else: + package = path + files_str = list(package.glob("**/*.py")) + files = [str(file.relative_to(".")) for file in files_str] + logger.info(f"Found {len(files)} files to process.") providers = {FullyQualifiedNameProvider, ScopeProvider}