From 992d0c3cc4f99223fbc335015338bb88e6b2d65b Mon Sep 17 00:00:00 2001 From: wendrul Date: Tue, 10 Mar 2026 18:24:04 +0100 Subject: [PATCH] wanr and fail if clibhaviour is higher than the current cli supports --- cli/src/commands/sync/sync.ts | 8 +------- cli/src/core/conf.ts | 18 ++++++++++++++++++ cli/test/cli_behavior.test.ts | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cli/src/commands/sync/sync.ts b/cli/src/commands/sync/sync.ts index 358d08f9c7..79f39047f7 100644 --- a/cli/src/commands/sync/sync.ts +++ b/cli/src/commands/sync/sync.ts @@ -45,6 +45,7 @@ import { import { getEffectiveSettings, mergeConfigWithConfigFile, + parseCliBehavior, SyncOptions, validateBranchConfiguration, } from "../../core/conf.ts"; @@ -104,13 +105,6 @@ import { getNonDottedPaths, } from "../../utils/resource_folders.ts"; -// Parse cliBehavior version string (e.g. "v1", "v2") into a number. Returns 0 if absent/invalid. -export function parseCliBehavior(value?: string): number { - if (!value) return 0; - const match = value.match(/^v(\d+)$/); - return match ? parseInt(match[1], 10) : 0; -} - // Merge CLI options with effective settings, preserving CLI flags as overrides function mergeCliWithEffectiveOptions< T extends GlobalOptions & SyncOptions & { repository?: string }, diff --git a/cli/src/core/conf.ts b/cli/src/core/conf.ts index 9177209b0d..5bd916cc31 100644 --- a/cli/src/core/conf.ts +++ b/cli/src/core/conf.ts @@ -14,6 +14,15 @@ import { execSync } from "node:child_process"; import { setNonDottedPaths } from "../utils/resource_folders.ts"; import type { PermissionedAsRule } from "./permissioned_as.ts"; +export const SUPPORTED_CLI_BEHAVIOR_VERSION = 1; + +// Parse cliBehavior version string (e.g. "v1", "v2") into a number. Returns 0 if absent/invalid. +export function parseCliBehavior(value?: string): number { + if (!value) return 0; + const match = value.match(/^v(\d+)$/); + return match ? parseInt(match[1], 10) : 0; +} + export let showDiffs = false; export function setShowDiffs(value: boolean) { showDiffs = value; @@ -294,6 +303,15 @@ export async function readConfigFile(): Promise { // Initialize global nonDottedPaths setting from config setNonDottedPaths(conf?.nonDottedPaths ?? false); + // Exit if the config specifies a cliBehavior version higher than what this CLI supports + const cliBehaviorVersion = parseCliBehavior(conf?.cliBehavior); + if (cliBehaviorVersion > SUPPORTED_CLI_BEHAVIOR_VERSION) { + log.error( + `Your wmill.yaml specifies cliBehavior: ${conf!.cliBehavior}, but this CLI only supports up to v${SUPPORTED_CLI_BEHAVIOR_VERSION}. Run 'wmill upgrade' to update.` + ); + process.exit(1); + } + return typeof conf == "object" ? conf : ({} as SyncOptions); } catch (e) { if ( diff --git a/cli/test/cli_behavior.test.ts b/cli/test/cli_behavior.test.ts index 8ddf254f78..2b4c0802ef 100644 --- a/cli/test/cli_behavior.test.ts +++ b/cli/test/cli_behavior.test.ts @@ -1,5 +1,5 @@ import { expect, test, describe } from "bun:test"; -import { parseCliBehavior } from "../src/commands/sync/sync.ts"; +import { parseCliBehavior } from "../src/core/conf.ts"; describe("parseCliBehavior", () => { test("parses v1 to 1", () => {