Files
cs249r_book/tinytorch/tito/commands/system/system.py
Vijay Janapa Reddi 7f01c24f09 feat: add 'tito system reset' command for pristine state reset
New command that resets TinyTorch to a clean state:
- Clears modules/ directory (all numbered module folders)
- Clears tinytorch/core/ (all .py except __init__.py)
- Optionally resets progress tracking (--keep-progress to skip)

Usage:
  tito system reset           # Interactive confirmation
  tito system reset --force   # Skip confirmation
  tito system reset --ci      # CI mode with exit codes
  tito system reset --keep-progress  # Keep completion history

This is useful for:
- Testing fresh install experience
- CI/CD pipeline resets
- Starting over with a clean slate
2026-01-23 14:54:07 -05:00

126 lines
4.3 KiB
Python

"""
System command group for TinyTorch CLI: environment, configuration, and system tools.
"""
from argparse import ArgumentParser, Namespace
from rich.panel import Panel
from ..base import BaseCommand
from .info import InfoCommand
from .health import HealthCommand
from .jupyter import JupyterCommand
from .update import UpdateCommand
from .logo import LogoCommand
from .reset import SystemResetCommand
class SystemCommand(BaseCommand):
@property
def name(self) -> str:
return "system"
@property
def description(self) -> str:
return "System environment and configuration commands"
def add_arguments(self, parser: ArgumentParser) -> None:
subparsers = parser.add_subparsers(
dest='system_command',
help='System subcommands',
metavar='SUBCOMMAND'
)
# Info subcommand
info_parser = subparsers.add_parser(
'info',
help='Show system and environment information'
)
info_cmd = InfoCommand(self.config)
info_cmd.add_arguments(info_parser)
# Health subcommand
health_parser = subparsers.add_parser(
'health',
help='Environment health check and validation'
)
health_cmd = HealthCommand(self.config)
health_cmd.add_arguments(health_parser)
# Jupyter subcommand
jupyter_parser = subparsers.add_parser(
'jupyter',
help='Start Jupyter notebook server'
)
jupyter_cmd = JupyterCommand(self.config)
jupyter_cmd.add_arguments(jupyter_parser)
# Update subcommand
update_parser = subparsers.add_parser(
'update',
help='Check for and install updates'
)
update_cmd = UpdateCommand(self.config)
update_cmd.add_arguments(update_parser)
# Logo subcommand
logo_parser = subparsers.add_parser(
'logo',
help='Learn about the TinyTorch logo and its meaning'
)
logo_cmd = LogoCommand(self.config)
logo_cmd.add_arguments(logo_parser)
# Reset subcommand
reset_parser = subparsers.add_parser(
'reset',
help='Reset TinyTorch to pristine state (clear modules and core)'
)
reset_cmd = SystemResetCommand(self.config)
reset_cmd.add_arguments(reset_parser)
def run(self, args: Namespace) -> int:
console = self.console
if not hasattr(args, 'system_command') or not args.system_command:
console.print(Panel(
"[bold cyan]System Commands[/bold cyan]\n\n"
"Available subcommands:\n"
" • [bold]info[/bold] - Show system/environment information\n"
" • [bold]health[/bold] - Environment health check and validation\n"
" • [bold]jupyter[/bold] - Start Jupyter notebook server\n"
" • [bold]update[/bold] - Check for and install updates\n"
" • [bold]logo[/bold] - Learn about the TinyTorch logo\n"
" • [bold]reset[/bold] - Reset to pristine state (clear modules/core)\n\n"
"[dim]Example: tito system health[/dim]",
title="System Command Group",
border_style="bright_cyan"
))
return 0
# Execute the appropriate subcommand
if args.system_command == 'info':
cmd = InfoCommand(self.config)
return cmd.execute(args)
elif args.system_command == 'health':
cmd = HealthCommand(self.config)
return cmd.execute(args)
elif args.system_command == 'jupyter':
cmd = JupyterCommand(self.config)
return cmd.execute(args)
elif args.system_command == 'update':
cmd = UpdateCommand(self.config)
return cmd.execute(args)
elif args.system_command == 'logo':
cmd = LogoCommand(self.config)
return cmd.execute(args)
elif args.system_command == 'reset':
cmd = SystemResetCommand(self.config)
return cmd.execute(args)
else:
console.print(Panel(
f"[red]Unknown system subcommand: {args.system_command}[/red]",
title="Error",
border_style="red"
))
return 1