generated from coulomb/repo-seed
chore: add local consistency sync cli
This commit is contained in:
@@ -365,6 +365,57 @@ def cmd_ingest_sbom(args: argparse.Namespace) -> None:
|
||||
sys.exit(result.returncode)
|
||||
|
||||
|
||||
def cmd_fix_consistency(args: argparse.Namespace) -> None:
|
||||
"""Run ADR-001 consistency repair from any registered repo checkout."""
|
||||
checker = STATE_HUB_DIR / "scripts" / "consistency_check.py"
|
||||
if not checker.exists():
|
||||
print(f"ERROR: consistency checker not found at {checker}")
|
||||
print(" Run this command from an editable state-hub install or the state-hub repo.")
|
||||
sys.exit(1)
|
||||
|
||||
if args.remote and not (args.repo or args.all):
|
||||
print("ERROR: --remote requires --repo or --all.")
|
||||
print(" From a local checkout, run: statehub fix-consistency")
|
||||
print(" For pull-before-fix, run: statehub fix-consistency --repo <slug> --remote")
|
||||
sys.exit(1)
|
||||
|
||||
cmd = [sys.executable, str(checker)]
|
||||
if args.all:
|
||||
cmd.append("--all")
|
||||
elif args.repo:
|
||||
cmd.extend(["--repo", args.repo])
|
||||
if args.repo_path:
|
||||
cmd.extend(["--repo-path", str(Path(args.repo_path).expanduser().resolve())])
|
||||
else:
|
||||
cmd.append("--here")
|
||||
if args.path:
|
||||
cmd.append(str(Path(args.path).expanduser().resolve()))
|
||||
|
||||
cmd.append("--fix")
|
||||
if args.remote:
|
||||
cmd.append("--remote")
|
||||
if args.no_writeback:
|
||||
cmd.append("--no-writeback")
|
||||
if args.archive_closed:
|
||||
cmd.append("--archive-closed")
|
||||
if args.archive_workplan:
|
||||
cmd.extend(["--archive-workplan", args.archive_workplan])
|
||||
if args.archive_date:
|
||||
cmd.extend(["--archive-date", args.archive_date])
|
||||
if args.api_base:
|
||||
cmd.extend(["--api-base", args.api_base])
|
||||
if args.as_json:
|
||||
cmd.append("--json")
|
||||
if args.max_seconds is not None:
|
||||
cmd.extend(["--max-seconds", str(args.max_seconds)])
|
||||
|
||||
result = subprocess.run(cmd)
|
||||
exit_code = result.returncode
|
||||
if exit_code == 2 and not args.strict_warnings:
|
||||
exit_code = 0
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
def cmd_create_workstream(args: argparse.Namespace) -> None:
|
||||
"""Create a workstream under a domain's topic."""
|
||||
_api_get("/state/health")
|
||||
@@ -582,6 +633,30 @@ def main() -> None:
|
||||
ing.add_argument("--slug", default=None, help="Repo slug (auto-detected from path if omitted)")
|
||||
ing.add_argument("--dry-run", action="store_true", help="Parse lockfiles but do not submit to API")
|
||||
|
||||
# fix-consistency
|
||||
fix = sub.add_parser(
|
||||
"fix-consistency",
|
||||
help="Reconcile workplan files with State Hub from the current repo",
|
||||
)
|
||||
target = fix.add_mutually_exclusive_group()
|
||||
target.add_argument("--repo", default=None, help="Registered repo slug; defaults to inferring from --path")
|
||||
target.add_argument("--all", action="store_true", help="Fix all registered repos with a visible path")
|
||||
fix.add_argument("--path", default=os.getcwd(), help="Repo checkout to infer from (defaults to cwd)")
|
||||
fix.add_argument("--repo-path", default=None, help="Override repo path when using --repo")
|
||||
fix.add_argument("--remote", action="store_true", help="Pull before fixing; requires --repo or --all")
|
||||
fix.add_argument("--max-seconds", type=int, default=None, help="Wall-clock budget for --remote --all")
|
||||
fix.add_argument("--no-writeback", action="store_true", help="Disable DB-to-file status writeback")
|
||||
fix.add_argument("--archive-closed", action="store_true", help="Archive closed root workplans after fixing")
|
||||
fix.add_argument("--archive-workplan", default=None, help="Archive only the matching workplan id or filename")
|
||||
fix.add_argument("--archive-date", default=None, help="YYMMDD archive prefix for --archive-closed")
|
||||
fix.add_argument("--api-base", default=API_BASE, help="State Hub API base URL")
|
||||
fix.add_argument("--json", action="store_true", dest="as_json", help="Output JSON from the checker")
|
||||
fix.add_argument(
|
||||
"--strict-warnings",
|
||||
action="store_true",
|
||||
help="Preserve checker exit code 2 for warnings-only runs",
|
||||
)
|
||||
|
||||
# create-workstream
|
||||
cws = sub.add_parser("create-workstream", help="Create a workstream under a domain topic")
|
||||
cws.add_argument("--domain", required=True, help="Domain slug to create the workstream under")
|
||||
@@ -644,6 +719,8 @@ def main() -> None:
|
||||
cmd_register(args)
|
||||
elif args.command == "ingest-sbom":
|
||||
cmd_ingest_sbom(args)
|
||||
elif args.command == "fix-consistency":
|
||||
cmd_fix_consistency(args)
|
||||
elif args.command == "create-workstream":
|
||||
cmd_create_workstream(args)
|
||||
elif args.command == "create-task":
|
||||
|
||||
Reference in New Issue
Block a user