diff --git a/src/index.ts b/src/index.ts index a33d266..9c73532 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,21 @@ async function main() { .description("The San Francisco Compute command line tool.") .version(pkg.version); + // Hydrate `account_id` before registering commands so feature-flag-gated + // surfaces (e.g. `--enable-infiniband` on `sf nodes create`) resolve + // correctly on the very first CLI invocation after login, rather than only + // appearing after the cache has been seeded by a previous run. + const config = await loadConfig(); + let exchangeAccountId = config.account_id; + if (!exchangeAccountId) { + const client = await apiClient(config.auth_token); + const { data } = await client.GET("/v1/account/me", {}); + if (data?.id) { + exchangeAccountId = data.id; + await saveConfig({ ...config, account_id: data.id }); + } + } + // commands registerLogin(program); registerContracts(program); @@ -84,18 +99,6 @@ async function main() { process.exit(0); }); - const config = await loadConfig(); - let exchangeAccountId = config.account_id; - - if (!exchangeAccountId) { - const client = await apiClient(config.auth_token); - const { data } = await client.GET("/v1/account/me", {}); - if (data?.id) { - exchangeAccountId = data.id; - saveConfig({ ...config, account_id: data.id }); - } - } - program.exitOverride((error) => { let isError = true; diff --git a/src/lib/nodes/create.ts b/src/lib/nodes/create.ts index 73e2b55..1841ac3 100644 --- a/src/lib/nodes/create.ts +++ b/src/lib/nodes/create.ts @@ -21,6 +21,7 @@ import { } from "../../helpers/units.ts"; import { handleNodesError, nodesClient } from "../../nodesClient.ts"; import { GPUS_PER_NODE } from "../constants.ts"; +import { isFeatureEnabled } from "../posthog.ts"; import { createNodesTable, durationOption, @@ -68,149 +69,153 @@ function validateCount(val: string): number { return parsed; } -const create = new Command("create") - .description("Create reserved or auto reserved nodes") - .showHelpAfterError() - .argument( - "[names...]", - "[Required: names or --count] Names of the nodes to create (must be unique across your account)", - ) - .option( - "-n, --count ", - "[Required: names or --count] Number of nodes to create with auto-generated names", - validateCount, - ) - .addOption( - new Option( - "-z, --zone ", - "[Required: zone or --any-zone if --auto is provided] Zone for your nodes", - ).conflicts("any-zone"), - ) - .addOption( - new Option("--any-zone", "Use any zone that meets requirements").conflicts( - "zone", - ), - ) - .addOption(maxPriceOption) - .addOption( - new Option( - "--reserved", - "Create reserved nodes (default). Reserved nodes have an explicit start and end time.", - ).conflicts("auto"), - ) - .addOption( - new Option( - "--auto", - "Create auto-reserved nodes. Auto-reserved nodes self-extend until they are released.", - ).conflicts("reserved"), - ) - .addOption(startOrNowOption) - .addOption(endOption.conflicts("duration")) - .addOption(durationOption.conflicts("end")) - .option( - "-u, --user-data