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

✨ Support single files via CLI #86

Merged
merged 2 commits into from
Jul 12, 2023
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
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