|
| 1 | +"""sourceosctl CLI entry point.""" |
| 2 | + |
| 3 | +import argparse |
| 4 | +import sys |
| 5 | + |
| 6 | +from sourceosctl import __version__ |
| 7 | +from sourceosctl.commands import ( |
| 8 | + doctor, |
| 9 | + profiles, |
| 10 | + nlboot, |
| 11 | + release, |
| 12 | + fingerprint, |
| 13 | + ai, |
| 14 | + agents, |
| 15 | +) |
| 16 | + |
| 17 | + |
| 18 | +def build_parser() -> argparse.ArgumentParser: |
| 19 | + """Build and return the argument parser.""" |
| 20 | + parser = argparse.ArgumentParser( |
| 21 | + prog="sourceosctl", |
| 22 | + description="SourceOS developer and AI operator CLI (read-only / dry-run surface)", |
| 23 | + ) |
| 24 | + parser.add_argument( |
| 25 | + "--version", action="version", version=f"sourceosctl {__version__}" |
| 26 | + ) |
| 27 | + |
| 28 | + sub = parser.add_subparsers(dest="command", metavar="<command>") |
| 29 | + sub.required = True |
| 30 | + |
| 31 | + # --- doctor --- |
| 32 | + doctor_p = sub.add_parser("doctor", help="Run environment health checks") |
| 33 | + doctor_p.set_defaults(func=doctor.run) |
| 34 | + |
| 35 | + # --- profiles --- |
| 36 | + profiles_p = sub.add_parser("profiles", help="Profile management") |
| 37 | + profiles_sub = profiles_p.add_subparsers(dest="profiles_command", metavar="<subcommand>") |
| 38 | + profiles_sub.required = True |
| 39 | + profiles_list_p = profiles_sub.add_parser("list", help="List available profiles") |
| 40 | + profiles_list_p.set_defaults(func=profiles.list_profiles) |
| 41 | + |
| 42 | + # --- nlboot --- |
| 43 | + nlboot_p = sub.add_parser("nlboot", help="NLBoot operator helpers") |
| 44 | + nlboot_sub = nlboot_p.add_subparsers(dest="nlboot_command", metavar="<subcommand>") |
| 45 | + nlboot_sub.required = True |
| 46 | + nlboot_evidence_p = nlboot_sub.add_parser("evidence", help="NLBoot evidence helpers") |
| 47 | + nlboot_evidence_sub = nlboot_evidence_p.add_subparsers( |
| 48 | + dest="nlboot_evidence_command", metavar="<subcommand>" |
| 49 | + ) |
| 50 | + nlboot_evidence_sub.required = True |
| 51 | + nlboot_inspect_p = nlboot_evidence_sub.add_parser( |
| 52 | + "inspect", help="Inspect a NLBoot evidence file" |
| 53 | + ) |
| 54 | + nlboot_inspect_p.add_argument("path", help="Path to NLBoot evidence JSON file") |
| 55 | + nlboot_inspect_p.set_defaults(func=nlboot.inspect_evidence) |
| 56 | + |
| 57 | + # --- release --- |
| 58 | + release_p = sub.add_parser("release", help="Release artifact inspection") |
| 59 | + release_sub = release_p.add_subparsers(dest="release_command", metavar="<subcommand>") |
| 60 | + release_sub.required = True |
| 61 | + release_inspect_p = release_sub.add_parser("inspect", help="Inspect a release artifact") |
| 62 | + release_inspect_p.add_argument("path", help="Path to release artifact JSON file") |
| 63 | + release_inspect_p.set_defaults(func=release.inspect) |
| 64 | + |
| 65 | + # --- fingerprint --- |
| 66 | + fingerprint_p = sub.add_parser("fingerprint", help="Environment fingerprint utilities") |
| 67 | + fingerprint_sub = fingerprint_p.add_subparsers( |
| 68 | + dest="fingerprint_command", metavar="<subcommand>" |
| 69 | + ) |
| 70 | + fingerprint_sub.required = True |
| 71 | + fingerprint_collect_p = fingerprint_sub.add_parser( |
| 72 | + "collect", help="Collect environment fingerprint (dry-run only)" |
| 73 | + ) |
| 74 | + fingerprint_collect_p.add_argument( |
| 75 | + "--dry-run", |
| 76 | + action="store_true", |
| 77 | + default=True, |
| 78 | + dest="dry_run", |
| 79 | + help="Print what would be collected without writing to disk (default: True)", |
| 80 | + ) |
| 81 | + fingerprint_collect_p.set_defaults(func=fingerprint.collect) |
| 82 | + |
| 83 | + # --- ai --- |
| 84 | + ai_p = sub.add_parser("ai", help="AI operator utilities") |
| 85 | + ai_sub = ai_p.add_subparsers(dest="ai_command", metavar="<subcommand>") |
| 86 | + ai_sub.required = True |
| 87 | + ai_labs_p = ai_sub.add_parser("labs", help="AI lab helpers") |
| 88 | + ai_labs_sub = ai_labs_p.add_subparsers(dest="ai_labs_command", metavar="<subcommand>") |
| 89 | + ai_labs_sub.required = True |
| 90 | + ai_labs_list_p = ai_labs_sub.add_parser("list", help="List available AI labs") |
| 91 | + ai_labs_list_p.set_defaults(func=ai.list_labs) |
| 92 | + |
| 93 | + # --- agents --- |
| 94 | + agents_p = sub.add_parser("agents", help="Agent sandbox helpers") |
| 95 | + agents_sub = agents_p.add_subparsers(dest="agents_command", metavar="<subcommand>") |
| 96 | + agents_sub.required = True |
| 97 | + agents_sandbox_p = agents_sub.add_parser("sandbox", help="Agent sandbox management") |
| 98 | + agents_sandbox_sub = agents_sandbox_p.add_subparsers( |
| 99 | + dest="agents_sandbox_command", metavar="<subcommand>" |
| 100 | + ) |
| 101 | + agents_sandbox_sub.required = True |
| 102 | + agents_sandbox_plan_p = agents_sandbox_sub.add_parser( |
| 103 | + "plan", help="Plan agent sandbox (dry-run only)" |
| 104 | + ) |
| 105 | + agents_sandbox_plan_p.add_argument( |
| 106 | + "--dry-run", |
| 107 | + action="store_true", |
| 108 | + default=True, |
| 109 | + dest="dry_run", |
| 110 | + help="Print plan without executing (default: True)", |
| 111 | + ) |
| 112 | + agents_sandbox_plan_p.set_defaults(func=agents.sandbox_plan) |
| 113 | + |
| 114 | + return parser |
| 115 | + |
| 116 | + |
| 117 | +def main(argv=None) -> int: |
| 118 | + """Main entry point. Returns exit code.""" |
| 119 | + parser = build_parser() |
| 120 | + args = parser.parse_args(argv) |
| 121 | + return args.func(args) or 0 |
| 122 | + |
| 123 | + |
| 124 | +if __name__ == "__main__": |
| 125 | + sys.exit(main()) |
0 commit comments