Skip to content

Commit

Permalink
✨ Support single files via CLI (#86)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <[email protected]>
  • Loading branch information
lemonyte and Kludex committed Jul 12, 2023
1 parent ca399ab commit 481ec10
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ bump-pydantic --help
To check the diff before applying the changes, you can run:

```bash
bump-pydantic --diff <package>
bump-pydantic --diff <path>
```

### Apply changes

To apply the changes, you can run:

```bash
bump-pydantic <package>
bump-pydantic <path>
```

## Rules
Expand Down
12 changes: 9 additions & 3 deletions bump_pydantic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}
Expand Down

0 comments on commit 481ec10

Please sign in to comment.