Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions cortex/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
print_all_preferences,
format_preference_value
)
from cortex.preflight_checker import PreflightChecker, format_report, export_report
from cortex.branding import (
console,
cx_print,
Expand Down Expand Up @@ -111,6 +112,11 @@
sys.stdout.write('\r\033[K')
sys.stdout.flush()

def install(self, software: str, execute: bool = False, dry_run: bool = False, simulate: bool = False):

Check warning on line 115 in cortex/cli.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused function parameter "execute".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSs&open=AZr9it4TOHUXk6syDWSs&pullRequest=264

Check warning on line 115 in cortex/cli.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the unused function parameter "dry_run".

See more on https://sonarcloud.io/project/issues?id=cortexlinux_cortex&issues=AZr9it4TOHUXk6syDWSt&open=AZr9it4TOHUXk6syDWSt&pullRequest=264
# Handle simulation mode first - no API key needed
if simulate:
return self._run_simulation(software)

def install(self, software: str, execute: bool = False, dry_run: bool = False):
# Validate input first
is_valid, error = validate_install_request(software)
Expand Down Expand Up @@ -245,6 +251,30 @@
history.update_installation(install_id, InstallationStatus.FAILED, str(e))
self._print_error(f"Unexpected error: {str(e)}")
return 1

def _run_simulation(self, software: str) -> int:
"""Run preflight simulation check for installation"""
try:
# Get API key for LLM-powered package info (optional).
api_key = os.environ.get('OPENAI_API_KEY') or os.environ.get('ANTHROPIC_API_KEY')
provider = self._get_provider() if api_key else 'openai'

# Create checker with optional API key for enhanced accuracy
checker = PreflightChecker(api_key=api_key, provider=provider)
report = checker.run_all_checks(software)

# Print formatted report
output = format_report(report, software)
print(output)

# Return error code if blocking issues found
if report.errors:
return 1
return 0

except Exception as e:
self._print_error(f"Simulation failed: {str(e)}")
return 1

def history(self, limit: int = 20, status: Optional[str] = None, show_id: Optional[str] = None):
"""Show installation history"""
Expand Down Expand Up @@ -799,6 +829,19 @@
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
cortex install docker
cortex install docker --execute
cortex install docker --simulate
cortex install "python 3.11 with pip"
cortex install nginx --dry-run
cortex history
cortex history show <id>
cortex rollback <id>
cortex check-pref
cortex check-pref ai.model
cortex edit-pref set ai.model gpt-4
cortex edit-pref delete theme
cortex edit-pref reset-all
cortex demo # See Cortex in action (no API key needed)
cortex install docker # Plan docker installation
cortex install docker --execute # Actually install docker
Expand Down Expand Up @@ -832,6 +875,7 @@
install_parser.add_argument('software', type=str, help='Software to install (natural language)')
install_parser.add_argument('--execute', action='store_true', help='Execute the generated commands')
install_parser.add_argument('--dry-run', action='store_true', help='Show commands without executing')
install_parser.add_argument('--simulate', action='store_true', help='Simulate installation without making changes')

# History command
history_parser = subparsers.add_parser('history', help='View installation history')
Expand Down Expand Up @@ -867,6 +911,8 @@
cli = CortexCLI(verbose=args.verbose)

try:
if args.command == 'install':
return cli.install(args.software, execute=args.execute, dry_run=args.dry_run, simulate=args.simulate)
if args.command == 'demo':
return cli.demo()
elif args.command == 'wizard':
Expand Down
Loading
Loading