forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand.tsx
More file actions
51 lines (49 loc) · 1.86 KB
/
Copy pathcommand.tsx
File metadata and controls
51 lines (49 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { getErrorMessage } from '../../errors';
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
import { handleUpdate } from './action';
import type { Command } from '@commander-js/extra-typings';
import { Text, render } from 'ink';
export const registerUpdate = (program: Command) => {
program
.command('update')
.description(COMMAND_DESCRIPTIONS.update)
.option('-c, --check', 'Check for updates without installing')
.action(async options => {
try {
render(<Text>Checking for updates...</Text>);
const result = await handleUpdate(options.check ?? false);
switch (result.status) {
case 'up-to-date':
render(<Text color="green">You are already on the latest version ({result.currentVersion})</Text>);
break;
case 'newer-local':
render(
<Text color="yellow">
Your version ({result.currentVersion}) is newer than the published version ({result.latestVersion})
</Text>
);
break;
case 'update-available':
render(
<Text>
Update available: {result.currentVersion} → <Text color="green">{result.latestVersion}</Text>
</Text>
);
render(<Text>Run `agentcore update` to install the update.</Text>);
break;
case 'updated':
render(<Text color="green">Successfully updated to {result.latestVersion}</Text>);
break;
case 'update-failed':
render(
<Text color="red">Failed to install update. Try running: npm install -g @aws/agentcore@latest</Text>
);
process.exit(1);
break;
}
} catch (error) {
render(<Text color="red">Error: {getErrorMessage(error)}</Text>);
process.exit(1);
}
});
};