@altertable/cli 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +245 -159
  2. package/package.json +4 -4
package/dist/cli.js CHANGED
@@ -7411,7 +7411,7 @@ function _isValueFlag(flag, argsDef) {
7411
7411
  }
7412
7412
 
7413
7413
  // src/version.ts
7414
- var VERSION = "1.2.0";
7414
+ var VERSION = "1.3.0";
7415
7415
  var USER_AGENT = `altertable-cli/${VERSION}`;
7416
7416
 
7417
7417
  // src/lib/transport-defaults.ts
@@ -7532,6 +7532,7 @@ var ENV_SCHEMA = {
7532
7532
  HOME: { parse: optional },
7533
7533
  NO_COLOR: { parse: optional },
7534
7534
  OSC_HYPERLINK: { parse: optional },
7535
+ PATH: { parse: optional },
7535
7536
  SHELL: { parse: optional },
7536
7537
  SSH_CONNECTION: { parse: optional },
7537
7538
  TERM: { parse: optional },
@@ -7567,12 +7568,6 @@ function copyProcessEnv() {
7567
7568
  return { ...process.env };
7568
7569
  }
7569
7570
  function validateEnvironment(source = process.env) {
7570
- const knownNames = new Set(Object.keys(ENV_SCHEMA));
7571
- const unknownNames = Object.keys(source).filter((name) => name.startsWith("ALTERTABLE_") && !knownNames.has(name)).sort();
7572
- if (unknownNames.length > 0) {
7573
- const noun = unknownNames.length === 1 ? "variable" : "variables";
7574
- throw new ConfigurationError(`Unknown Altertable environment ${noun}: ${unknownNames.join(", ")}. Check the spelling against the documented ALTERTABLE_* variables.`);
7575
- }
7576
7571
  for (const name of Object.keys(ENV_SCHEMA)) {
7577
7572
  if (name.startsWith("ALTERTABLE_")) {
7578
7573
  readEnvFrom(source, name);
@@ -8262,11 +8257,6 @@ function kvUnset(filePath, key) {
8262
8257
  }
8263
8258
  } catch {}
8264
8259
  }
8265
- function chmodConfigFile(filePath) {
8266
- try {
8267
- chmodSync(filePath, 384);
8268
- } catch {}
8269
- }
8270
8260
 
8271
8261
  // src/lib/profile-store.ts
8272
8262
  var DEFAULT_PROFILE_NAME = "default";
@@ -8457,10 +8447,6 @@ function isQueryLayout(value) {
8457
8447
  function configGetGlobal(key) {
8458
8448
  return kvGet(configFile(), key);
8459
8449
  }
8460
- function configSetGlobal(key, value) {
8461
- kvSet(configFile(), key, value);
8462
- chmodConfigFile(configFile());
8463
- }
8464
8450
  function resolveAllowInsecureHttp() {
8465
8451
  return readEnv("ALTERTABLE_ALLOW_INSECURE_HTTP") ?? false;
8466
8452
  }
@@ -10040,7 +10026,22 @@ function readArgvFlagValue(argv, flagName) {
10040
10026
  }
10041
10027
 
10042
10028
  // src/lib/global-flags.ts
10043
- var GLOBAL_ARGV_FLAGS_WITH_VALUE = new Set(["--profile", "--connect-timeout", "--read-timeout"]);
10029
+ var GLOBAL_ARGV_FLAGS_WITH_VALUE = new Set([
10030
+ "--profile",
10031
+ "--connect-timeout",
10032
+ "--read-timeout"
10033
+ ]);
10034
+ var GLOBAL_ARGV_BOOLEAN_FLAGS = new Set([
10035
+ "--debug",
10036
+ "-d",
10037
+ "--json",
10038
+ "--agent",
10039
+ "--no-color"
10040
+ ]);
10041
+ function isGlobalArgvFlag(argument) {
10042
+ const flag = argument.split("=", 1)[0] ?? argument;
10043
+ return GLOBAL_ARGV_BOOLEAN_FLAGS.has(flag) || GLOBAL_ARGV_FLAGS_WITH_VALUE.has(flag);
10044
+ }
10044
10045
  function findFirstSubcommandIndex(argv) {
10045
10046
  for (let index = 0;index < argv.length; index += 1) {
10046
10047
  const arg = argv[index];
@@ -19979,15 +19980,23 @@ function extractFlags(command) {
19979
19980
  }
19980
19981
  return flags.sort((left, right) => left.name.localeCompare(right.name));
19981
19982
  }
19982
- function resolveSubcommandName(_key, command) {
19983
+ function resolveAliases(value) {
19984
+ if (!value) {
19985
+ return [];
19986
+ }
19987
+ const aliases = Array.isArray(value) ? value : [value];
19988
+ return aliases.map(String);
19989
+ }
19990
+ function resolveSubcommandNames(command) {
19983
19991
  const meta = command.meta;
19984
19992
  if (meta && typeof meta === "object" && "hidden" in meta && meta.hidden) {
19985
- return;
19993
+ return [];
19986
19994
  }
19987
19995
  if (meta && typeof meta === "object" && "name" in meta && meta.name) {
19988
- return String(meta.name);
19996
+ const aliases = "alias" in meta ? resolveAliases(meta.alias) : [];
19997
+ return [...new Set([String(meta.name), ...aliases])];
19989
19998
  }
19990
- return;
19999
+ return [];
19991
20000
  }
19992
20001
  function resolveMetaDescription(command) {
19993
20002
  const meta = command.meta;
@@ -20003,6 +20012,15 @@ function resolveRootName(root) {
20003
20012
  }
20004
20013
  return "altertable";
20005
20014
  }
20015
+ function walkSubcommands(subcommands, depth) {
20016
+ if (!subcommands) {
20017
+ return [];
20018
+ }
20019
+ return Object.values(subcommands).flatMap((subcommand) => {
20020
+ const command = subcommand;
20021
+ return resolveSubcommandNames(command).map((name) => walkCommand(name, command, depth));
20022
+ }).sort((left, right) => left.name.localeCompare(right.name));
20023
+ }
20006
20024
  function walkCommand(name, command, depth) {
20007
20025
  const node = {
20008
20026
  name,
@@ -20013,14 +20031,7 @@ function walkCommand(name, command, depth) {
20013
20031
  if (depth >= MAX_SUBCOMMAND_DEPTH || !command.subCommands) {
20014
20032
  return node;
20015
20033
  }
20016
- const subcommands = Object.entries(command.subCommands).map(([key, subcommand]) => {
20017
- const resolvedName = resolveSubcommandName(key, subcommand);
20018
- if (!resolvedName) {
20019
- return;
20020
- }
20021
- return walkCommand(resolvedName, subcommand, depth + 1);
20022
- }).filter((entry) => entry !== undefined).sort((left, right) => left.name.localeCompare(right.name));
20023
- node.subcommands = subcommands;
20034
+ node.subcommands = walkSubcommands(command.subCommands, depth + 1);
20024
20035
  return node;
20025
20036
  }
20026
20037
  function buildCompletionSpec(root) {
@@ -20033,13 +20044,7 @@ function buildCompletionSpec(root) {
20033
20044
  if (!root.subCommands) {
20034
20045
  return spec;
20035
20046
  }
20036
- spec.subcommands = Object.entries(root.subCommands).map(([key, subcommand]) => {
20037
- const resolvedName = resolveSubcommandName(key, subcommand);
20038
- if (!resolvedName) {
20039
- return;
20040
- }
20041
- return walkCommand(resolvedName, subcommand, 1);
20042
- }).filter((entry) => entry !== undefined).sort((left, right) => left.name.localeCompare(right.name));
20047
+ spec.subcommands = walkSubcommands(root.subCommands, 1);
20043
20048
  return spec;
20044
20049
  }
20045
20050
  function collectCompletionContexts(root) {
@@ -20742,6 +20747,60 @@ function hasObjectKey(value, key) {
20742
20747
  return key in value;
20743
20748
  }
20744
20749
 
20750
+ // src/lib/executable-path.ts
20751
+ import { accessSync, constants, realpathSync, statSync as statSync3 } from "fs";
20752
+ import { delimiter, isAbsolute, resolve as resolve2 } from "path";
20753
+ function canonicalPath(path) {
20754
+ try {
20755
+ return realpathSync(path);
20756
+ } catch {
20757
+ return path;
20758
+ }
20759
+ }
20760
+ function isExecutableFile(path) {
20761
+ try {
20762
+ if (!statSync3(path).isFile()) {
20763
+ return false;
20764
+ }
20765
+ accessSync(path, constants.X_OK);
20766
+ return true;
20767
+ } catch {
20768
+ return false;
20769
+ }
20770
+ }
20771
+ function invocationPath(value, cwd, pathValue) {
20772
+ if (isAbsolute(value)) {
20773
+ return isExecutableFile(value) ? value : undefined;
20774
+ }
20775
+ if (value.includes("/") || value.includes("\\")) {
20776
+ const candidate = resolve2(cwd, value);
20777
+ return isExecutableFile(candidate) ? candidate : undefined;
20778
+ }
20779
+ for (const directory of pathValue.split(delimiter)) {
20780
+ const candidate = resolve2(directory || cwd, value);
20781
+ if (isExecutableFile(candidate)) {
20782
+ return candidate;
20783
+ }
20784
+ }
20785
+ return;
20786
+ }
20787
+ function resolveProcessExecutablePath(options = {}) {
20788
+ const usesCurrentProcess = options.execPath === undefined;
20789
+ const execPath = options.execPath ?? process.execPath;
20790
+ const argv0 = options.argv0 ?? (usesCurrentProcess ? process.argv0 : execPath);
20791
+ const cwd = options.cwd ?? process.cwd();
20792
+ const pathValue = options.path ?? "";
20793
+ if (isAbsolute(execPath)) {
20794
+ return canonicalPath(execPath);
20795
+ }
20796
+ const invokedPath = invocationPath(argv0, cwd, pathValue);
20797
+ if (invokedPath) {
20798
+ return canonicalPath(invokedPath);
20799
+ }
20800
+ const resolvedExecPath = invocationPath(execPath, cwd, pathValue) ?? resolve2(cwd, execPath);
20801
+ return canonicalPath(resolvedExecPath);
20802
+ }
20803
+
20745
20804
  // src/package-metadata.ts
20746
20805
  var CLI_PACKAGE_METADATA = {
20747
20806
  name: "@altertable/cli",
@@ -20805,10 +20864,27 @@ var UpdaterIntervalsMs = {
20805
20864
  never: Number.POSITIVE_INFINITY
20806
20865
  };
20807
20866
  var UpdaterInstallCommands = {
20808
- bun: { command: "bun", argsBeforePackage: ["install", "-g"] },
20809
- npm: { command: "npm", argsBeforePackage: ["install", "-g"] },
20810
- pnpm: { command: "pnpm", argsBeforePackage: ["add", "-g"] },
20811
- yarn: { command: "yarn", argsBeforePackage: ["global", "add"] }
20867
+ bun: {
20868
+ command: "bun",
20869
+ argsBeforePackage: ["install", "-g"],
20870
+ globalBinArgs: ["pm", "bin", "-g"]
20871
+ },
20872
+ npm: {
20873
+ command: "npm",
20874
+ argsBeforePackage: ["install", "-g"],
20875
+ globalBinArgs: ["prefix", "-g"],
20876
+ globalBinIsPrefix: true
20877
+ },
20878
+ pnpm: {
20879
+ command: "pnpm",
20880
+ argsBeforePackage: ["add", "-g"],
20881
+ globalBinArgs: ["bin", "-g"]
20882
+ },
20883
+ yarn: {
20884
+ command: "yarn",
20885
+ argsBeforePackage: ["global", "add"],
20886
+ globalBinArgs: ["global", "bin"]
20887
+ }
20812
20888
  };
20813
20889
  var UpdaterInstallMethod = {
20814
20890
  auto: "auto",
@@ -20847,7 +20923,7 @@ var UpdaterConfig = {
20847
20923
  manual: 1e4
20848
20924
  },
20849
20925
  intervalsMs: UpdaterIntervalsMs,
20850
- automaticCheckSkipCommands: ["completion", "update"],
20926
+ automaticCheckSkipCommands: ["completion", "update", "upgrade"],
20851
20927
  installCommands: UpdaterInstallCommands,
20852
20928
  installMethods: UpdaterInstallMethodConfig,
20853
20929
  releasePlatforms: RELEASE_PLATFORM_CONFIG,
@@ -20864,12 +20940,10 @@ var UpdaterConfig = {
20864
20940
  bunExecutablePrefix: "bun-"
20865
20941
  },
20866
20942
  commands: {
20867
- selfUpdate: "altertable update --install"
20943
+ selfUpdate: "altertable update"
20868
20944
  }
20869
20945
  };
20870
- var UpdaterSources = objectKeys(UpdaterConfig.sources);
20871
20946
  var UpdaterCheckIntervals = objectKeys(UpdaterConfig.intervalsMs);
20872
- var UpdaterInstallMethods = objectKeys(UpdaterConfig.installMethods);
20873
20947
 
20874
20948
  // src/lib/updater.ts
20875
20949
  var AUTO_SKIP_COMMANDS = new Set(UpdaterConfig.automaticCheckSkipCommands);
@@ -20902,6 +20976,9 @@ function comparePrereleaseIdentifier(left, right) {
20902
20976
  function normalizeVersion(version) {
20903
20977
  return version.trim().replace(/^v/i, "");
20904
20978
  }
20979
+ function isValidVersion(version) {
20980
+ return parseVersion(version) !== undefined;
20981
+ }
20905
20982
  function compareVersions(leftVersion, rightVersion) {
20906
20983
  const left = parseVersion(leftVersion);
20907
20984
  const right = parseVersion(rightVersion);
@@ -20974,9 +21051,6 @@ function tryWriteUpdateState(state) {
20974
21051
  writeUpdateState(state);
20975
21052
  } catch {}
20976
21053
  }
20977
- function clearUpdateState() {
20978
- rmSync4(updaterStateFile(), { force: true });
20979
- }
20980
21054
  function parseUpdateCheckInterval(value) {
20981
21055
  if (isAllowedValue(UpdaterCheckIntervals, value)) {
20982
21056
  return value;
@@ -20987,9 +21061,6 @@ function getUpdateCheckInterval() {
20987
21061
  const fromConfig = parseUpdateCheckInterval(configGetGlobal(UpdaterConfig.configKeys.checkInterval));
20988
21062
  return fromConfig ?? UpdaterConfig.defaults.checkInterval;
20989
21063
  }
20990
- function setUpdateCheckInterval(interval) {
20991
- configSetGlobal(UpdaterConfig.configKeys.checkInterval, interval);
20992
- }
20993
21064
  function resolveUpdateSource(source) {
20994
21065
  return source ?? readEnv("ALTERTABLE_UPDATE_SOURCE") ?? UpdaterConfig.defaults.source;
20995
21066
  }
@@ -21286,7 +21357,10 @@ function pathEndsWithAny(filePath, suffixes) {
21286
21357
  return suffixes.some((suffix) => pathEndsWith(filePath, suffix));
21287
21358
  }
21288
21359
  function detectCurrentInstallation(options = {}) {
21289
- const execPath = options.execPath ?? process.execPath;
21360
+ const execPath = resolveProcessExecutablePath({
21361
+ ...options,
21362
+ path: options.path ?? readEnv("PATH")
21363
+ });
21290
21364
  const argv = options.argv ?? process.argv;
21291
21365
  const scriptPath = argv[1] ?? "";
21292
21366
  const execName = basename2(execPath);
@@ -21389,7 +21463,7 @@ function resolveGitHubBinaryTarget(options) {
21389
21463
  const targetPath = options.targetPath ?? installation.executablePath;
21390
21464
  if (!options.targetPath && installation.kind !== UpdaterInstallationKind.nativeBinary) {
21391
21465
  throw new CliError("Self-update is only supported for native release binaries.", {
21392
- details: "Use --install-method package-manager for npm-style installs, or pass --target-path for controlled binary replacement."
21466
+ details: "Install the published package with your package manager, or use a native release binary."
21393
21467
  });
21394
21468
  }
21395
21469
  return targetPath;
@@ -21448,7 +21522,8 @@ async function installGitHubBinaryRelease(version, options = {}) {
21448
21522
  }
21449
21523
  function runInstallPlan(plan, options = {}) {
21450
21524
  const stdio = options.stdio ?? "inherit";
21451
- const result = (options.spawnImpl ?? spawnSync4)(plan.command, plan.args, { stdio });
21525
+ const spawnImpl = options.spawnImpl ?? spawnSync4;
21526
+ const result = spawnImpl(plan.command, plan.args, { stdio });
21452
21527
  if (result.error) {
21453
21528
  throw new CliError(`Unable to run ${plan.command}.`, { cause: result.error });
21454
21529
  }
@@ -21464,7 +21539,27 @@ function runInstallPlan(plan, options = {}) {
21464
21539
  if (options.verify === false) {
21465
21540
  return normalizeVersion(options.expectedVersion ?? "");
21466
21541
  }
21467
- return verifyInstalledCliVersion(options.expectedVersion ?? plan.args[plan.args.length - 1]?.split("@").pop() ?? "", options.verifyCommand ?? "altertable", options.spawnImpl);
21542
+ const verifyCommand = options.verifyCommand ?? (options.verifyGlobalInstall ? resolveGlobalInstalledCliPath(plan.manager, spawnImpl) : "altertable");
21543
+ return verifyInstalledCliVersion(options.expectedVersion ?? plan.args[plan.args.length - 1]?.split("@").pop() ?? "", verifyCommand, spawnImpl);
21544
+ }
21545
+ function resolveGlobalInstalledCliPath(manager, spawnImpl) {
21546
+ const config = UpdaterConfig.installCommands[manager];
21547
+ const result = spawnImpl(config.command, [...config.globalBinArgs], { encoding: "utf8" });
21548
+ if (result.error) {
21549
+ throw new CliError(`Unable to locate the ${manager} global binary directory.`, {
21550
+ cause: result.error
21551
+ });
21552
+ }
21553
+ if (result.status !== 0) {
21554
+ throw new CliError(`${manager} global binary directory lookup failed with exit code ${result.status ?? 1}.`);
21555
+ }
21556
+ const outputPath = spawnOutputText(result.stdout).trim();
21557
+ if (!outputPath) {
21558
+ throw new CliError(`${manager} did not report its global binary directory.`);
21559
+ }
21560
+ const binDirectory = "globalBinIsPrefix" in config && config.globalBinIsPrefix && process.platform !== "win32" ? join4(outputPath, "bin") : outputPath;
21561
+ const executableName = process.platform === "win32" ? `${UpdaterConfig.executableName}.cmd` : UpdaterConfig.executableName;
21562
+ return join4(binDirectory, executableName);
21468
21563
  }
21469
21564
  function installPackageManagerRelease(version, options = {}) {
21470
21565
  const plan = createInstallPlan(version);
@@ -21472,6 +21567,7 @@ function installPackageManagerRelease(version, options = {}) {
21472
21567
  stdio: options.stdio,
21473
21568
  spawnImpl: options.spawnImpl,
21474
21569
  expectedVersion: version,
21570
+ verifyGlobalInstall: options.installation?.kind === UpdaterInstallationKind.source,
21475
21571
  verify: options.verify
21476
21572
  });
21477
21573
  return {
@@ -21489,7 +21585,7 @@ async function installCliUpdate(version, options = {}) {
21489
21585
  if (method === UpdaterInstallMethod.githubBinary) {
21490
21586
  return await installGitHubBinaryRelease(version, { ...options, installation });
21491
21587
  }
21492
- return installPackageManagerRelease(version, options);
21588
+ return installPackageManagerRelease(version, { ...options, installation });
21493
21589
  }
21494
21590
  function recommendedInstallCommand(version, installation = detectCurrentInstallation()) {
21495
21591
  if (installation.kind === UpdaterInstallationKind.packageManager) {
@@ -21606,7 +21702,28 @@ async function maybeShowUpdateNotice(options) {
21606
21702
  }
21607
21703
  } catch {}
21608
21704
  }
21609
- function formatUpdateResult(result) {
21705
+ function formatUpdateResult(result, targetVersion) {
21706
+ if (targetVersion) {
21707
+ const target = normalizeVersion(targetVersion);
21708
+ const current = normalizeVersion(result.current_version);
21709
+ const comparison = compareVersions(target, current);
21710
+ if (comparison < 0) {
21711
+ return [
21712
+ renderDisplayText([
21713
+ span(`Target version v${target} is older than installed altertable v${current}.`)
21714
+ ]),
21715
+ renderDisplayText([
21716
+ span("Run "),
21717
+ span(`altertable update ${target} --force`, "accent"),
21718
+ span(" to install it anyway.")
21719
+ ])
21720
+ ].join(`
21721
+ `);
21722
+ }
21723
+ if (comparison === 0) {
21724
+ return renderDisplayText([span(`Target version v${target} is already installed.`)]);
21725
+ }
21726
+ }
21610
21727
  if (!result.update_available) {
21611
21728
  return renderDisplayText([
21612
21729
  span("Congrats!", "success"),
@@ -21627,26 +21744,51 @@ function formatUpdateResult(result) {
21627
21744
  ].join(`
21628
21745
  `);
21629
21746
  }
21630
- function formatUpdateStatus(interval, state) {
21631
- const statusRows = [{ label: "Auto update checks:", value: interval }];
21632
- if (state.last_checked_at) {
21633
- statusRows.push({ label: "Last checked:", value: state.last_checked_at });
21634
- }
21635
- if (state.latest_version) {
21636
- statusRows.push({ label: "Cached latest:", value: state.latest_version });
21637
- }
21638
- if (state.last_error) {
21639
- statusRows.push({ label: "Last error:", value: state.last_error });
21640
- }
21641
- if (!existsSync4(updaterStateFile())) {
21642
- statusRows.push({ label: "Cache:", value: "empty" });
21643
- }
21644
- return renderDocumentText(document(section(rows(statusRows))));
21645
- }
21646
21747
 
21647
21748
  // src/commands/update.ts
21648
- function buildTargetResult(targetVersion, source) {
21749
+ var DEFAULT_DEPENDENCIES = { checkForUpdate, installCliUpdate };
21750
+ var UPDATE_OPTIONS = new Set(["--check", "--force"]);
21751
+ function validateUpdateArguments(rawArgs) {
21752
+ let versionSeen = false;
21753
+ for (let index = 0;index < rawArgs.length; index += 1) {
21754
+ const argument = rawArgs[index];
21755
+ if (argument === undefined) {
21756
+ continue;
21757
+ }
21758
+ if (argument === "--") {
21759
+ continue;
21760
+ }
21761
+ if (argument.startsWith("-")) {
21762
+ const option = argument.split("=", 1)[0] ?? argument;
21763
+ if (isGlobalArgvFlag(argument)) {
21764
+ if (!argument.includes("=") && GLOBAL_ARGV_FLAGS_WITH_VALUE.has(option)) {
21765
+ index += 1;
21766
+ }
21767
+ continue;
21768
+ }
21769
+ if (!UPDATE_OPTIONS.has(option)) {
21770
+ throw new CliError(`Unknown option ${option}.`, {
21771
+ details: "Run altertable update --help for usage."
21772
+ });
21773
+ }
21774
+ continue;
21775
+ }
21776
+ if (versionSeen) {
21777
+ throw new CliError(`Unexpected argument for altertable update: ${argument}.`, {
21778
+ details: "Pass at most one version; run altertable update --help for usage."
21779
+ });
21780
+ }
21781
+ versionSeen = true;
21782
+ }
21783
+ }
21784
+ function buildTargetResult(targetVersion) {
21649
21785
  const version = normalizeVersion(targetVersion);
21786
+ if (!isValidVersion(version)) {
21787
+ throw new CliError(`Invalid update version: ${targetVersion}.`, {
21788
+ details: "Expected a semantic version such as 1.2.0 or 1.3.0-rc.1."
21789
+ });
21790
+ }
21791
+ const source = resolveUpdateSource();
21650
21792
  return {
21651
21793
  current_version: VERSION,
21652
21794
  latest_version: version,
@@ -21657,119 +21799,63 @@ function buildTargetResult(targetVersion, source) {
21657
21799
  install_command: recommendedInstallCommand(version)
21658
21800
  };
21659
21801
  }
21660
- async function writeStatus(sink) {
21661
- const interval = getUpdateCheckInterval();
21662
- const state = readUpdateState();
21802
+ async function writeUpdateCheck(result, targetVersion, sink) {
21663
21803
  await writeCommandOutput({
21664
21804
  kind: "normalized",
21665
- data: {
21666
- update_check_interval: interval,
21667
- state
21668
- },
21669
- humanText: formatUpdateStatus(interval, state)
21805
+ data: result,
21806
+ humanText: formatUpdateResult(result, targetVersion)
21670
21807
  }, sink);
21671
21808
  }
21672
- async function runUpdateCommand(args, sink) {
21673
- const interval = args["check-interval"];
21674
- if (interval) {
21675
- setUpdateCheckInterval(interval);
21676
- }
21677
- if (args["clear-cache"]) {
21678
- clearUpdateState();
21679
- }
21680
- if (args.status && !args.install && !args["target-version"]) {
21681
- await writeStatus(sink);
21809
+ async function executeUpdateCommand(args, sink, dependencies = DEFAULT_DEPENDENCIES) {
21810
+ const targetVersion = asCliArgString(args.version);
21811
+ const result = targetVersion ? buildTargetResult(targetVersion) : await dependencies.checkForUpdate();
21812
+ if (args.check) {
21813
+ await writeUpdateCheck(result, targetVersion, sink);
21682
21814
  return;
21683
21815
  }
21684
- if (interval && !args["clear-cache"] && !args.install && !args["target-version"]) {
21685
- await writeStatus(sink);
21686
- return;
21816
+ if (!args.force && targetVersion && compareVersions(result.latest_version, result.current_version) < 0) {
21817
+ throw new CliError(`Target version v${result.latest_version} is older than v${VERSION}.`);
21687
21818
  }
21688
- const source = args.source ?? UpdaterConfig.defaults.source;
21689
- const targetVersion = asCliArgString(args["target-version"]);
21690
- const result = targetVersion ? buildTargetResult(targetVersion, source) : await checkForUpdate({ source });
21691
- if (!args.install) {
21692
- await writeCommandOutput({
21693
- kind: "normalized",
21694
- data: result,
21695
- humanText: formatUpdateResult(result)
21696
- }, sink);
21819
+ if (!args.force && !result.update_available) {
21820
+ await writeUpdateCheck(result, targetVersion, sink);
21697
21821
  return;
21698
21822
  }
21699
- if (!result.update_available && !args.force) {
21700
- throw new CliError(targetVersion ? "Target version is not newer than the installed CLI. Pass --force to install it anyway." : "altertable is already up to date. Pass --force to reinstall the current latest version.");
21701
- }
21702
- const method = args["install-method"] ?? UpdaterConfig.defaults.installMethod;
21703
- const methodLabel = method === "auto" ? "automatic installer" : method;
21704
- sink.writeMetadata([`Running ${methodLabel} for altertable ${result.latest_version}`]);
21705
- const installed = await installCliUpdate(result.latest_version, {
21706
- method,
21707
- targetPath: asCliArgString(args["target-path"]),
21823
+ sink.writeMetadata([`Updating altertable to ${result.latest_version}`]);
21824
+ const installed = await dependencies.installCliUpdate(result.latest_version, {
21708
21825
  stdio: sink.json ? "pipe" : "inherit"
21709
21826
  });
21710
21827
  await writeCommandOutput({
21711
21828
  kind: "ack",
21712
- data: {
21713
- ...installed
21714
- },
21829
+ data: installed,
21715
21830
  metadataMessage: `altertable ${installed.verified_version} installed.`
21716
21831
  }, sink);
21717
21832
  }
21718
21833
  var updateCommand = defineAltertableCommand({
21719
21834
  meta: {
21720
21835
  name: "update",
21836
+ alias: ["upgrade"],
21721
21837
  commandGroup: "platform",
21722
- description: "Check for a newer Altertable CLI release and optionally install it.",
21723
- examples: [
21724
- "altertable update",
21725
- "altertable update --install",
21726
- "altertable update --status",
21727
- "altertable update --check-interval never"
21728
- ]
21838
+ description: "Update Altertable CLI to the latest release.",
21839
+ examples: ["altertable update", "altertable update --check", "altertable update 1.2.0 --force"]
21729
21840
  },
21730
21841
  args: {
21731
- install: {
21732
- type: "boolean",
21733
- description: "Install the latest available release after the update check succeeds."
21734
- },
21735
- force: {
21736
- type: "boolean",
21737
- description: "Reinstall the selected release even when it is not newer than the current CLI."
21738
- },
21739
- source: {
21740
- type: "enum",
21741
- options: [...UpdaterSources],
21742
- description: `Where to look for release metadata: npm or GitHub (default: ${UpdaterConfig.defaults.source}).`
21743
- },
21744
- "target-version": {
21745
- type: "string",
21746
- description: "Use an explicit version instead of discovering the latest release."
21747
- },
21748
- "install-method": {
21749
- type: "enum",
21750
- options: [...UpdaterInstallMethods],
21751
- description: `How --install applies the update: auto, package-manager, or github-binary (default: ${UpdaterConfig.defaults.installMethod}).`
21752
- },
21753
- "target-path": {
21754
- type: "string",
21755
- description: "Replace this binary path when using --install-method github-binary."
21842
+ version: {
21843
+ type: "positional",
21844
+ description: "Specific version to install (default: latest).",
21845
+ required: false
21756
21846
  },
21757
- status: {
21847
+ check: {
21758
21848
  type: "boolean",
21759
- description: "Show the automatic update-check policy and cached latest-release state."
21849
+ description: "Check for an update without installing it."
21760
21850
  },
21761
- "clear-cache": {
21851
+ force: {
21762
21852
  type: "boolean",
21763
- description: "Delete cached update metadata before continuing."
21764
- },
21765
- "check-interval": {
21766
- type: "enum",
21767
- options: [...UpdaterCheckIntervals],
21768
- description: "Set how often successful human-facing commands may show update notices."
21853
+ description: "Reinstall or downgrade to the selected release."
21769
21854
  }
21770
21855
  },
21771
- async run({ args, sink }) {
21772
- await runUpdateCommand(args, sink);
21856
+ async run({ args, rawArgs, sink }) {
21857
+ validateUpdateArguments(rawArgs);
21858
+ await executeUpdateCommand(args, sink);
21773
21859
  }
21774
21860
  });
21775
21861
 
@@ -22279,7 +22365,6 @@ async function bootstrap() {
22279
22365
  applyTerminalColorFromContext(earlyContext);
22280
22366
  setCliContext(earlyContext);
22281
22367
  try {
22282
- validateEnvironment();
22283
22368
  const earlyExit = findEarlyBootstrapExit(rawArgs);
22284
22369
  if (earlyExit?.id === "help") {
22285
22370
  const [command, parent] = await resolveSubCommandForUsage(main, rawArgs);
@@ -22294,6 +22379,7 @@ async function bootstrap() {
22294
22379
  console.log(VERSION);
22295
22380
  return;
22296
22381
  }
22382
+ validateEnvironment();
22297
22383
  await runCommand(main, { rawArgs });
22298
22384
  await maybeShowUpdateNotice({
22299
22385
  context: getCliContext(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altertable/cli",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Altertable CLI — query and manage your data platform",
5
5
  "homepage": "https://github.com/altertable-ai/altertable-cli#readme",
6
6
  "bugs": {
@@ -34,11 +34,11 @@
34
34
  "release:build": "bun run scripts/release.ts build",
35
35
  "release:finalize": "bun run scripts/release.ts finalize",
36
36
  "release:matrix": "bun run scripts/release.ts matrix",
37
- "release:publish-github": "bun run scripts/github-release.ts publish",
38
- "release:publish-npm": "bun run scripts/publish-npm.ts",
37
+ "release:publish-github": "bun run scripts/publish-release.ts publish-github",
38
+ "release:publish-npm": "bun run scripts/publish-release.ts publish-npm",
39
39
  "release:smoke": "bun run scripts/release.ts smoke",
40
40
  "release:verify": "bun run scripts/release.ts verify",
41
- "release:upload-github": "bun run scripts/github-release.ts upload",
41
+ "release:upload-github": "bun run scripts/publish-release.ts upload-github",
42
42
  "pack:check": "bun run build && bun pm pack --dry-run",
43
43
  "knip": "knip"
44
44
  },