Skip to content

Commit

Permalink
feat: Add callable for ssort
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Apr 13, 2023
1 parent 6cb775d commit 11b54da
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/duty/callables/ssort.py
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

0 comments on commit 11b54da

Please sign in to comment.