-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Callable for [ssort](https://github.com/bwhmather/ssort).""" | ||
|
||
from __future__ import annotations | ||
|
||
import sys | ||
|
||
from failprint.lazy import lazy | ||
|
||
|
||
@lazy(name="ssort") | ||
def run( | ||
*files: str, | ||
diff: bool | None = None, | ||
check: bool | None = None, | ||
) -> int: | ||
r"""Run `ssort`. | ||
Parameters: | ||
*files: Files to format. | ||
diff: Prints a diff of all changes ssort would make to a file. | ||
check: Check the file for unsorted statements. Returns 0 if nothing needs to be changed. Otherwise returns 1. | ||
""" | ||
from ssort._main import main as ssort | ||
|
||
cli_args = list(files) | ||
|
||
if diff: | ||
cli_args.append("--diff") | ||
|
||
if check: | ||
cli_args.append("--check") | ||
|
||
old_sys_argv = sys.argv | ||
sys.argv = ["ssort*", *cli_args] | ||
try: | ||
return ssort() | ||
finally: | ||
sys.argv = old_sys_argv |