Implement F007 explicit project profiles
This commit is contained in:
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Record an explicitly selected business or personal project profile."""
|
||||
import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
from forge.profile_config import build_record, read_flat_record, write_record # noqa: E402
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--project", type=Path, required=True, help="existing new/legacy project directory")
|
||||
parser.add_argument("--profile", choices=("business", "personal"), required=True)
|
||||
parser.add_argument("--owner", required=True)
|
||||
parser.add_argument("--brand", required=True)
|
||||
parser.add_argument("--contributor-access", required=True, help="documented project policy, not an access grant")
|
||||
parser.add_argument("--testing", required=True)
|
||||
parser.add_argument("--deployment", required=True)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
record = build_record(ROOT / "profiles" / f"{args.profile}.yaml", profile=args.profile,
|
||||
ownership=args.owner, branding=args.brand,
|
||||
contributor_access=args.contributor_access,
|
||||
testing_expectations=args.testing,
|
||||
deployment_expectations=args.deployment)
|
||||
if not args.project.is_dir() or args.project.is_symlink():
|
||||
raise ValueError("project must be an existing, non-symlink directory")
|
||||
target = args.project / ".bortstack" / "profile.yaml"
|
||||
if target.parent.is_symlink():
|
||||
raise ValueError("profile directory must not be a symlink")
|
||||
if target.exists() or target.is_symlink():
|
||||
raise FileExistsError(f"profile already exists: {target}")
|
||||
if args.dry_run:
|
||||
print(f"PLAN {args.profile} -> {target}")
|
||||
else:
|
||||
write_record(args.project, record)
|
||||
print(f"WROTE {target}")
|
||||
read_flat_record(target)
|
||||
except (OSError, ValueError) as exc:
|
||||
parser.exit(1, f"ERROR: {exc}\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user