feat: implement slice 1 tracer bullet (cli entrypoint, distro detector, and test suite)
This commit is contained in:
commit
63c6cc846b
16 files changed
+1317
No files matched your search
@@ -0,0 +1,135 @@
|
||||
import argparse
|
||||
import sys
|
||||
from typing import List, Optional
|
||||
|
||||
from linux_updater import __version__
|
||||
from linux_updater.core.detector import DistroDetector
|
||||
from linux_updater.models import DistroFamily
|
||||
|
||||
|
||||
def create_parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="linux-updater",
|
||||
description="Unified, safe multi-distribution Linux system updater and health inspector.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v", "--version",
|
||||
action="version",
|
||||
version=f"%(prog)s {__version__}",
|
||||
help="Show program's version number and exit.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-c", "--config",
|
||||
type=str,
|
||||
default="/etc/linux-updater.json",
|
||||
help="Path to JSON configuration file.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-y", "--yes", "--non-interactive",
|
||||
dest="non_interactive",
|
||||
action="store_true",
|
||||
help="Run without interactive confirmation prompts (ideal for cron and automation).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--dry-run",
|
||||
action="store_true",
|
||||
help="Simulate execution without modifying system state.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-remediation",
|
||||
action="store_true",
|
||||
help="Disable automatic remediation of failed pre-flight health checks.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--skip-preflight",
|
||||
action="store_true",
|
||||
help="Skip pre-flight health checks (not recommended).",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--json",
|
||||
action="store_true",
|
||||
help="Output structured JSON results.",
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
|
||||
|
||||
# Subcommand: update
|
||||
update_parser = subparsers.add_parser(
|
||||
"update",
|
||||
help="Inspect health, auto-remediate safe issues, and apply package updates.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
update_parser.add_argument(
|
||||
"--packages",
|
||||
nargs="+",
|
||||
metavar="PACKAGE",
|
||||
help="Selectively update only the specified package(s) instead of the entire system.",
|
||||
)
|
||||
|
||||
# Subcommand: check
|
||||
subparsers.add_parser(
|
||||
"check",
|
||||
help="Check system health and list available updates without making modifications.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
|
||||
# Subcommand: release-upgrade
|
||||
release_parser = subparsers.add_parser(
|
||||
"release-upgrade",
|
||||
help="Perform a major distribution release upgrade with additional safety guardrails.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
release_parser.add_argument(
|
||||
"-t", "--target-release",
|
||||
type=str,
|
||||
help="Specify the target distribution version number/codename (e.g. 24.04, 41).",
|
||||
)
|
||||
|
||||
# Subcommand: clean
|
||||
clean_parser = subparsers.add_parser(
|
||||
"clean",
|
||||
help="Clean downloaded package cache and remove orphaned packages.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
clean_parser.add_argument(
|
||||
"--all",
|
||||
action="store_true",
|
||||
help="Clean both package cache and autoremove unused dependencies.",
|
||||
)
|
||||
|
||||
# Subcommand: health
|
||||
subparsers.add_parser(
|
||||
"health",
|
||||
help="Run only the pre-flight health diagnostic checks.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def main(argv: Optional[List[str]] = None) -> int:
|
||||
parser = create_parser()
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
# If no subcommand provided, default to update or show help if no args given
|
||||
if args.command is None:
|
||||
args.command = "update"
|
||||
|
||||
detector = DistroDetector()
|
||||
distro = detector.detect()
|
||||
|
||||
if not args.json:
|
||||
print(f"Linux System Updater v{__version__}")
|
||||
print(f"Detected System: {distro.pretty_name} (Family: {distro.family.value})")
|
||||
|
||||
if distro.family == DistroFamily.UNKNOWN:
|
||||
if not args.json:
|
||||
print(f"Error: Unsupported or unrecognized Linux distribution: {distro.distro_id}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user