From 01aef10d71d661d5004c87b10aefccbe435bf7de Mon Sep 17 00:00:00 2001 From: Daniel Tao Date: Tue, 9 Dec 2025 18:51:47 -0800 Subject: [PATCH 1/4] chore: update `sf vms ls` copy to nudge to use `sf nodes` --- src/lib/vm/list.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/vm/list.ts b/src/lib/vm/list.ts index e5072249..7926adb7 100644 --- a/src/lib/vm/list.ts +++ b/src/lib/vm/list.ts @@ -75,7 +75,7 @@ const list = new Command("list") return; } logAndQuit( - "You have no VMs. Buy a VM with: \n $ sf buy -t h100v -d 1h -n 8", + "You have no legacy VMs. Buy a VM with: \n $ sf nodes create --help", ); } From 78eb17f88f143587c7aa8e73118c301b33b4ffd9 Mon Sep 17 00:00:00 2001 From: Daniel Tao Date: Tue, 9 Dec 2025 18:52:04 -0800 Subject: [PATCH 2/4] feat: add deprecation warning banner to `sf vms` --- src/lib/vm/index.ts | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/lib/vm/index.ts b/src/lib/vm/index.ts index 0f3014c4..74793abc 100644 --- a/src/lib/vm/index.ts +++ b/src/lib/vm/index.ts @@ -1,4 +1,9 @@ -import { type Command } from "@commander-js/extra-typings"; +import { Command } from "@commander-js/extra-typings"; +import { red, yellow } from "jsr:@std/fmt/colors"; +import boxen from "boxen"; +import console from "node:console"; +import { nodesClient } from "../../nodesClient.ts"; +import { pluralizeNodes } from "../nodes/utils.ts"; import { registerSsh } from "./ssh.ts"; import { addImage } from "../nodes/image/index.ts"; import list from "./list.ts"; @@ -6,12 +11,49 @@ import logs from "./logs.ts"; import replace from "./replace.ts"; import script from "./script.ts"; +const DEPRECATION_WARNING = red(boxen( + `\x1b[31mWe're deprecating \x1b[37msf buy\x1b[31m and \x1b[37msf vm\x1b[31m for Virtual Machines.\x1b[31m +\x1b[31mWe recommend you create a VM Node instead: \x1b[37msf nodes create --help\x1b[31m +\x1b[37msf nodes\x1b[31m allows you to create, extend, and release specific machines directly.\x1b[31m`, + { + padding: 0.75, + borderColor: "red", + }, +)); + +async function getVMDeprecationWarning() { + const client = await nodesClient(); + const nodes = await client.nodes.list(); + const numNodesWithVMs = + nodes.data?.filter((node) => node.vms?.data?.length ?? 0 > 0).length ?? 0; + if (numNodesWithVMs > 0) { + return yellow( + boxen( + `You have \x1b[1m\x1b[33m${numNodesWithVMs} ${ + pluralizeNodes(numNodesWithVMs) + }\x1b[0m\x1b[33m with active or previous VMs. +Managing VM Nodes with deprecated \x1b[37msf vm\x1b[33m commands may cause undefined behavior. +Use \x1b[37msf nodes\x1b[33m to create, extend and release specific machines directly.`, + { + padding: 0.75, + borderColor: "yellow", + }, + ), + ); + } + return DEPRECATION_WARNING; +} export async function registerVM(program: Command) { const vm = program .command("vm") .showHelpAfterError() .aliases(["v", "vms"]) - .description("Manage virtual machines"); + .description("Manage virtual machines") + .hook("preAction", async () => { + const vmDeprecationWarning = await getVMDeprecationWarning(); + console.error(vmDeprecationWarning); + }) + .addHelpText("beforeAll", DEPRECATION_WARNING + "\n"); registerSsh(vm); From e25238345a534efd983a9dcad892a2e73f7200f4 Mon Sep 17 00:00:00 2001 From: Daniel Tao Date: Tue, 9 Dec 2025 18:52:16 -0800 Subject: [PATCH 3/4] fix: correctly mount `registerVM` --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5d530e5c..83b5b0d2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,7 +51,7 @@ registerUpgrade(program); await registerScale(program); registerClusters(program); registerMe(program); -registerVM(program); +await registerVM(program); await registerNodes(program); await registerZones(program); From ee5db340c93aa46cf2c844f4faeb5378aec0689b Mon Sep 17 00:00:00 2001 From: Daniel Tao Date: Tue, 9 Dec 2025 18:57:20 -0800 Subject: [PATCH 4/4] chore: use immediately executed function to capitalize pluralized nodes --- src/lib/vm/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/vm/index.ts b/src/lib/vm/index.ts index 74793abc..e8ded6b6 100644 --- a/src/lib/vm/index.ts +++ b/src/lib/vm/index.ts @@ -30,8 +30,10 @@ async function getVMDeprecationWarning() { return yellow( boxen( `You have \x1b[1m\x1b[33m${numNodesWithVMs} ${ - pluralizeNodes(numNodesWithVMs) - }\x1b[0m\x1b[33m with active or previous VMs. + // Capitalize the first letter of the word + ((word) => word.charAt(0).toUpperCase() + word.slice(1))( + pluralizeNodes(numNodesWithVMs), + )}\x1b[0m\x1b[33m with active or previous VMs. Managing VM Nodes with deprecated \x1b[37msf vm\x1b[33m commands may cause undefined behavior. Use \x1b[37msf nodes\x1b[33m to create, extend and release specific machines directly.`, {