Skip to content

Commit fe584de

Browse files
authored
feat: cli can update itself when prompted (#21)
1 parent 9edf8a7 commit fe584de

12 files changed

Lines changed: 200 additions & 292 deletions

File tree

RELEASE.md

Lines changed: 0 additions & 118 deletions
This file was deleted.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Breadcrumb.tsx

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,51 @@ export const Breadcrumb = ({
2121
const isDevEnvironment = env === "dev";
2222

2323
return (
24-
<Box marginBottom={1} paddingX={0} paddingY={0}>
25-
<Box
26-
borderStyle="round"
27-
borderColor={colors.primary}
28-
paddingX={2}
29-
paddingY={0}
30-
>
31-
<Text color={colors.primary} bold>
32-
rl
33-
</Text>
34-
{isDevEnvironment && (
35-
<Text color={colors.error} bold>
36-
{" "}
37-
(dev)
24+
<Box
25+
justifyContent="space-between"
26+
marginBottom={1}
27+
paddingX={0}
28+
paddingY={0}
29+
>
30+
<Box flexShrink={0}>
31+
<Box
32+
borderStyle="round"
33+
borderColor={colors.primary}
34+
paddingX={2}
35+
paddingY={0}
36+
>
37+
<Text color={colors.primary} bold>
38+
rl
3839
</Text>
39-
)}
40-
<Text color={colors.textDim}></Text>
41-
{items.map((item, index) => {
42-
// Limit label length to prevent Yoga layout engine errors
43-
const MAX_LABEL_LENGTH = 80;
44-
const truncatedLabel =
45-
item.label.length > MAX_LABEL_LENGTH
46-
? item.label.substring(0, MAX_LABEL_LENGTH) + "..."
47-
: item.label;
40+
{isDevEnvironment && (
41+
<Text color={colors.error} bold>
42+
{" "}
43+
(dev)
44+
</Text>
45+
)}
46+
<Text color={colors.textDim}></Text>
47+
{items.map((item, index) => {
48+
// Limit label length to prevent Yoga layout engine errors
49+
const MAX_LABEL_LENGTH = 80;
50+
const truncatedLabel =
51+
item.label.length > MAX_LABEL_LENGTH
52+
? item.label.substring(0, MAX_LABEL_LENGTH) + "..."
53+
: item.label;
4854

49-
return (
50-
<React.Fragment key={index}>
51-
<Text color={item.active ? colors.primary : colors.textDim}>
52-
{truncatedLabel}
53-
</Text>
54-
{index < items.length - 1 && (
55-
<Text color={colors.textDim}></Text>
56-
)}
57-
</React.Fragment>
58-
);
59-
})}
60-
</Box>
61-
{showVersionCheck && (
62-
<Box paddingX={2} marginTop={0}>
63-
<UpdateNotification />
55+
return (
56+
<React.Fragment key={index}>
57+
<Text color={item.active ? colors.primary : colors.textDim}>
58+
{truncatedLabel}
59+
</Text>
60+
{index < items.length - 1 && (
61+
<Text color={colors.textDim}></Text>
62+
)}
63+
</React.Fragment>
64+
);
65+
})}
6466
</Box>
65-
)}
67+
</Box>
68+
{showVersionCheck && <UpdateNotification />}
6669
</Box>
6770
);
6871
};

src/components/MainMenu.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import { Banner } from "./Banner.js";
55
import { Breadcrumb } from "./Breadcrumb.js";
66
import { VERSION } from "../version.js";
77
import { colors } from "../utils/theme.js";
8+
import { execCommand } from "../utils/exec.js";
89
import { useViewportHeight } from "../hooks/useViewportHeight.js";
910
import { useExitOnCtrlC } from "../hooks/useExitOnCtrlC.js";
11+
import { useUpdateCheck } from "../hooks/useUpdateCheck.js";
1012

1113
interface MenuItem {
1214
key: string;
@@ -51,6 +53,9 @@ export const MainMenu = ({ onSelect }: MainMenuProps) => {
5153
// Use centralized viewport hook for consistent layout
5254
const { terminalHeight } = useViewportHeight({ overhead: 0 });
5355

56+
// Check for updates
57+
const { updateAvailable } = useUpdateCheck();
58+
5459
// Handle Ctrl+C to exit
5560
useExitOnCtrlC();
5661

@@ -69,6 +74,12 @@ export const MainMenu = ({ onSelect }: MainMenuProps) => {
6974
onSelect("blueprints");
7075
} else if (input === "s" || input === "3") {
7176
onSelect("snapshots");
77+
} else if (input === "u" && updateAvailable) {
78+
// Release terminal and exec into update command (never returns)
79+
execCommand("sh", [
80+
"-c",
81+
"npm install -g @runloop/rl-cli@latest && exec rli",
82+
]);
7283
}
7384
});
7485

@@ -125,6 +136,7 @@ export const MainMenu = ({ onSelect }: MainMenuProps) => {
125136
{figures.arrowUp}
126137
{figures.arrowDown} Navigate • [1-3] Quick select • [Enter] Select •
127138
[Esc] Quit
139+
{updateAvailable && " • [u] Update"}
128140
</Text>
129141
</Box>
130142
</Box>
@@ -204,6 +216,7 @@ export const MainMenu = ({ onSelect }: MainMenuProps) => {
204216
{figures.arrowUp}
205217
{figures.arrowDown} Navigate • [1-3] Quick select • [Enter] Select •
206218
[Esc] Quit
219+
{updateAvailable && " • [u] Update"}
207220
</Text>
208221
</Box>
209222
</Box>

0 commit comments

Comments
 (0)