Read a project's language, title templates and branch template from its config
This commit is contained in:
@@ -38,8 +38,9 @@ false, and where `env-file` is asked for and not set. No path setting has a defa
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
from project_config.settings import CONFIG, ENV_FILE, load, ProjectConfig, SETTINGS, WAIT_FOR_APPROVAL
|
||||
from project_config.settings import CONFIG, ENV_FILE, load, OPTIONAL, ProjectConfig, SETTINGS, WAIT_FOR_APPROVAL
|
||||
from failure import Failure
|
||||
from project_config import templates
|
||||
from git_cli.git_repo import git, Git
|
||||
|
||||
|
||||
@@ -47,8 +48,8 @@ def main(argv: list[str]) -> int:
|
||||
if argv[:1] in (["-h"], ["--help"]):
|
||||
print(__doc__.strip())
|
||||
return 0
|
||||
if len(argv) > 1 or (argv and argv[0] not in (*SETTINGS, ENV_FILE, WAIT_FOR_APPROVAL)):
|
||||
print(f"usage: project-config [<setting>], where <setting> is one of {', '.join((*SETTINGS, ENV_FILE, WAIT_FOR_APPROVAL))}", file=sys.stderr)
|
||||
if len(argv) > 1 or (argv and argv[0] not in (*SETTINGS, *OPTIONAL)):
|
||||
print(f"usage: project-config [<setting>], where <setting> is one of {', '.join((*SETTINGS, *OPTIONAL))}", file=sys.stderr)
|
||||
return 1
|
||||
config = located(None, pathlib.Path.home())
|
||||
if isinstance(config, Failure):
|
||||
@@ -57,11 +58,15 @@ def main(argv: list[str]) -> int:
|
||||
if argv == [WAIT_FOR_APPROVAL]:
|
||||
print("true" if config.wait_for_approval else "false")
|
||||
return 0
|
||||
if argv and argv[0] in config.texts:
|
||||
print(config.texts[argv[0]])
|
||||
return 0
|
||||
paths = {**config.paths, **({ENV_FILE: config.env_file} if config.env_file else {})}
|
||||
if argv and argv[0] not in paths:
|
||||
print(f"{config.folder / CONFIG} sets no `{ENV_FILE}`", file=sys.stderr)
|
||||
return 1
|
||||
listed = [f"{name}: {path}" for name, path in paths.items()] + ([f"{WAIT_FOR_APPROVAL}: true"] if config.wait_for_approval else [])
|
||||
defaults = ProjectConfig(config.key, config.folder, config.top, {}).texts
|
||||
listed = [f"{name}: {path}" for name, path in paths.items()] + ([f"{WAIT_FOR_APPROVAL}: true"] if config.wait_for_approval else []) + [f"{name}: {text}" for name, text in config.texts.items() if text != defaults[name]]
|
||||
print(paths[argv[0]] if argv else "\n".join(listed))
|
||||
return 0
|
||||
|
||||
@@ -77,6 +82,12 @@ def located(directory: str | None, home: pathlib.Path, run: Git = git) -> Projec
|
||||
return load(pathlib.Path(lines[0]), pathlib.Path(lines[1]).parent, home)
|
||||
|
||||
|
||||
def commit_title(directory: str | None, home: pathlib.Path, run: Git = git) -> str:
|
||||
"""The `commit-title` template of the project whose checkout holds directory, else the current directory. A bare summary where no config names the checkout or its config cannot be read, as in a third party's clone, so every title there is read as it stands."""
|
||||
config = located(directory, home, run)
|
||||
return templates.TITLE if isinstance(config, Failure) else config.commit_title
|
||||
|
||||
|
||||
def project() -> ProjectConfig | Failure:
|
||||
"""The config of the project whose checkout holds the current directory, under the user's home."""
|
||||
return located(None, pathlib.Path.home())
|
||||
|
||||
Reference in New Issue
Block a user