Skip to content
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
5 changes: 3 additions & 2 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ are relevant for the hook's check. The default is `{defaultScope}`.

[NOTE]
--
All hooks have an optional `project-dir` arugument, which is useful for monorepos that do not have a `build.sbt` in their root.
All hooks have an optional `no-clean` arugument, which won't automatically run an `sbt clean` before executing the command.
All hooks have an optional `project-dir` argument, which is useful for monorepos that do not have a `build.sbt` in their root.
All hooks have an optional `no-clean` argument, which won't automatically run an `sbt clean` before executing the command.
All hooks have an optional `client` argument, which will persist the SBT session across invocations on newer SBT versions.
--

[IMPORTANT]
Expand Down
11 changes: 10 additions & 1 deletion pre_commit_hooks/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Opts:
project_dir: str | None = None
clean: bool = True
varargs: dict = field(default_factory=dict)
client: bool = False


def default_argparse(
Expand All @@ -28,12 +29,19 @@ def default_argparse(
default=False,
help="Turn off sbt clean. Default: False",
)
arg_p.add_argument(
"--client",
action="store_true",
default=False,
help="Run sbt in --client mode, persisting sessions across commits. Default: False",
)
for fn in additional_args:
fn(arg_p)
varags = vars(arg_p.parse_args(argv))
return Opts(
project_dir=varags.pop("project_dir", None),
clean=not varags.pop("no_clean", False),
client=varags.pop("client", False),
varargs=varags,
)

Expand All @@ -45,12 +53,13 @@ def run_sbt_command(
opts: Opts = Opts(),
):
print(f"Running SBT command: {task_def} with options: {opts}")
sbt_args = "--client" if opts.client else ""
if opts.clean:
task_def = f"; clean ; {task_def}"
else:
task_def = f"; {task_def}"
sbt_process = subprocess.run(
[f"sbt '{task_def}'"],
[f"sbt {sbt_args} '{task_def}'"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=True,
Expand Down