Skip to content
Open
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@ CLI Tools / scripts that augment us when working on Void Projects

>[!warning] Use at your own risk. This is firmly space trash.

Everything in this repo is completely vibe coded and likely never looked at. We use the tooling in here to augment our work and choose willingly to ignore the quality for the sake of quick tooling.
Everything in this repo is completely vibe coded and likely never looked at. We use the tooling in here to augment our work and choose willingly to ignore the quality for the sake of quick tooling.

## Installation

Requires [uv](https://docs.astral.sh/uv/).

```powershell
uv tool install -e .
```

## Usage

```
stcli [OPTIONS] COMMAND [ARGS]...
```

Blank `stcli` command prints help.
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[project]
name = "spacetrash"
version = "0.1.0"
description = "spacetrash CLI"
requires-python = ">=3.11"
dependencies = [
"typer>=0.12",
"rich>=13",
]

[project.scripts]
stcli = "stcli.main:app"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.hatch.build.targets.wheel]
packages = ["src/stcli"]
Empty file added src/stcli/__init__.py
Empty file.
Empty file added src/stcli/commands/__init__.py
Empty file.
68 changes: 68 additions & 0 deletions src/stcli/commands/wsl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import ctypes
import subprocess
import sys

import typer
from rich.console import Console

app = typer.Typer(
no_args_is_help=True,
help="Commands for managing the WSL environment.",
)
console = Console()


def _is_admin() -> bool:
try:
return bool(ctypes.windll.shell32.IsUserAnAdmin())
except Exception:
return False


def _relaunch_elevated() -> int:
# Spawns an elevated hidden PowerShell that runs the restart command,
# waits for it, and surfaces the exit code back to the caller.
ps_command = (
"$p = Start-Process powershell "
"-Verb RunAs "
"-ArgumentList '-NoProfile -NonInteractive -Command "
"\"try { Get-Service vmcompute -ErrorAction Stop | Restart-Service -ErrorAction Stop } "
"catch { exit 1 }\"' "
"-Wait -PassThru -WindowStyle Hidden; "
"exit $p.ExitCode"
)
result = subprocess.run(
["powershell", "-NonInteractive", "-Command", ps_command],
text=True,
)
return result.returncode


@app.command("fix")
def wsl_fix():
"""Restart the WSL vmcompute service (Windows only)."""
if sys.platform != "win32":
console.print("[yellow]wsl fix must be run from Windows, not from inside WSL.[/yellow]")
raise typer.Exit(1)

console.print("[cyan]Restarting vmcompute service...[/cyan]")

if _is_admin():
result = subprocess.run(
["powershell", "-NonInteractive", "-Command", "try { Get-Service vmcompute -ErrorAction Stop | Restart-Service -ErrorAction Stop } catch { exit 1 }"],
capture_output=True,
text=True,
)
returncode = result.returncode
stderr = result.stderr.strip()
else:
console.print("[dim]Elevation required — UAC prompt will appear.[/dim]")
returncode = _relaunch_elevated()
stderr = ""

if returncode == 0:
console.print("[green]vmcompute restarted successfully.[/green]")
else:
msg = f": {stderr}" if stderr else ""
console.print(f"[red]Failed to restart vmcompute{msg}[/red]")
raise typer.Exit(returncode)
9 changes: 9 additions & 0 deletions src/stcli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import typer
from stcli.commands import wsl

app = typer.Typer(name="stcli", no_args_is_help=True)
app.add_typer(wsl.app, name="wsl")


if __name__ == "__main__":
app()