-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement actual update execution for all installation methods #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfb4eaa
feat: implement actual update execution for all installation methods
pitzcarraldo 7f8033c
fix: surface update-check errors instead of reporting 'latest'
pitzcarraldo 3b80ba0
Merge branch 'main' into feat/update-command
pitzcarraldo c94a7ac
fix: address PR review feedback for update command
pitzcarraldo fb9511e
fix: correct misleading comment about binary auto-update support
pitzcarraldo fe37cec
fix: check canAutoUpdate before dry-run to reflect real execution beh…
pitzcarraldo 329daf0
chore: regenerate embedded-skills.ts with ios-setup skill
pitzcarraldo 63af078
fix: remove incorrect usesAgent flag from ios-setup skill
pitzcarraldo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,141 @@ | ||
| /** | ||
| * CLI update command - checks for and displays update information. | ||
| * CLI update command - checks for and executes updates. | ||
| * | ||
| * @module commands/update | ||
| */ | ||
|
|
||
| import readline from 'node:readline/promises'; | ||
| import { | ||
| checkForUpdate, | ||
| detectInstallationMethod, | ||
| getUpdateCommand, | ||
| executeUpdate, | ||
| planUpdate, | ||
| type UpdateOptions, | ||
| type UpdatePlan, | ||
| } from '../lib/services/update-service'; | ||
|
|
||
| /** | ||
| * Check for updates and display information. | ||
| * Display the update plan to the user. | ||
| */ | ||
| export async function updateCommand(): Promise<void> { | ||
| function displayUpdatePlan(plan: UpdatePlan): void { | ||
| console.log('\n=== Update Plan ===\n'); | ||
|
|
||
| console.log(`Installation method: ${plan.installMethod}`); | ||
| console.log(`Current version: ${plan.currentVersion}`); | ||
| console.log(`Latest version: ${plan.latestVersion}`); | ||
|
|
||
| if (!plan.hasUpdate) { | ||
| console.log('\nYou are already on the latest version.'); | ||
| return; | ||
| } | ||
|
|
||
| console.log(`\nUpdate command: ${plan.updateCommand}`); | ||
|
|
||
| if (!plan.canAutoUpdate) { | ||
| console.log('\nNote: Auto-update is not supported for this installation method.'); | ||
| console.log(`Please run manually:\n ${plan.updateCommand}`); | ||
| } | ||
|
|
||
| console.log(''); | ||
| } | ||
|
|
||
| /** | ||
| * Display the update result. | ||
| */ | ||
| function displayUpdateResult( | ||
| result: Awaited<ReturnType<typeof executeUpdate>>, | ||
| plan: UpdatePlan, | ||
| ): void { | ||
| console.log('\n=== Update Result ===\n'); | ||
|
|
||
| if (result.success) { | ||
| console.log(`✓ ${result.message}`); | ||
| } else { | ||
| console.log(`✗ ${result.message}`); | ||
| if (!plan.canAutoUpdate) { | ||
| console.log(`\nTo update manually, run:\n ${plan.updateCommand}`); | ||
| } | ||
| } | ||
| console.log(''); | ||
| } | ||
|
|
||
| /** | ||
| * Prompt user for confirmation. | ||
| */ | ||
| async function promptConfirmation(message: string): Promise<boolean> { | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout, | ||
| }); | ||
|
|
||
| try { | ||
| const answer = await rl.question(`${message} [y/N] `); | ||
| return answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes'; | ||
| } finally { | ||
| rl.close(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Execute the update command. | ||
| */ | ||
| export async function updateCommand( | ||
| options: UpdateOptions = { dryRun: false, force: false }, | ||
| ): Promise<void> { | ||
| console.log('Checking for updates...\n'); | ||
|
|
||
| try { | ||
| const [updateResult, installInfo] = await Promise.all([ | ||
| checkForUpdate(5000), // Use a longer timeout for CLI | ||
| detectInstallationMethod(), | ||
| ]); | ||
| // Plan the update (checks for updates and detects installation method) | ||
| const plan = await planUpdate(); | ||
|
|
||
| if (updateResult.error) { | ||
| console.error(`Failed to check for updates: ${updateResult.error}`); | ||
| // Check for update-check errors (network/registry failures) | ||
| if (plan.error) { | ||
| console.error(`Failed to check for updates: ${plan.error}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| if (!updateResult.hasUpdate) { | ||
| console.log(`You're on the latest version (${updateResult.currentVersion})`); | ||
| // No update available | ||
| if (!plan.hasUpdate) { | ||
| console.log(`You're on the latest version (${plan.currentVersion})`); | ||
| return; | ||
| } | ||
|
|
||
| // Display the plan | ||
| displayUpdatePlan(plan); | ||
|
|
||
| // Can't auto-update - stop here | ||
| if (!plan.canAutoUpdate) { | ||
| return; | ||
| } | ||
|
|
||
| const updateCmd = getUpdateCommand(installInfo); | ||
| console.log( | ||
| `Update available: ${updateResult.currentVersion} -> ${updateResult.latestVersion}`, | ||
| ); | ||
| console.log(`\nTo update, run:\n ${updateCmd}\n`); | ||
| // Dry run - stop here | ||
| if (options.dryRun) { | ||
| console.log('[DRY RUN] No changes were made.\n'); | ||
| return; | ||
| } | ||
|
|
||
| // Confirm with user | ||
| if (!options.force) { | ||
| const confirmed = await promptConfirmation( | ||
| `Update from ${plan.currentVersion} to ${plan.latestVersion}?`, | ||
| ); | ||
| if (!confirmed) { | ||
| console.log('\nUpdate cancelled.\n'); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Execute the update | ||
| console.log('\nUpdating...\n'); | ||
| const result = await executeUpdate(plan, options); | ||
|
|
||
| // Display the result | ||
| displayUpdateResult(result, plan); | ||
|
|
||
| if (!result.success) { | ||
| process.exit(1); | ||
| } | ||
| } catch (error) { | ||
| const errorMessage = error instanceof Error ? error.message : 'Unknown error'; | ||
| console.error(`Failed to check for updates: ${errorMessage}`); | ||
| console.error(`\nFailed to update: ${errorMessage}\n`); | ||
| process.exit(1); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.