Files
soleprint/soleprint/common/slice/cli/common.py
2026-09-24 00:43:18 -03:00

26 lines
650 B
Python

"""What every command does the same way — written once."""
from pathlib import Path
ROOT = __package__.rsplit(".", 1)[0]
PROG = f"python3 -m {ROOT}"
class Abort(Exception):
"""An expected failure. Printed as one line, exit 1 — never a traceback."""
def kb(n: int) -> str:
return f"{n / 1024:.1f} KB"
def load_runfile(path: Path):
from .. import runfile, tokens
if not path.exists():
raise Abort(f"no run file at {path} — see soleprint/common/slice/ui.example.toml")
try:
return runfile.load(path, tokens.available_themes())
except runfile.ConfigError as e:
raise Abort(str(e)) from None