wanr and fail if clibhaviour is higher than the current cli supports

This commit is contained in:
wendrul
2026-03-10 18:24:04 +01:00
parent fac0dab3b4
commit 992d0c3cc4
3 changed files with 20 additions and 8 deletions
+1 -7
View File
@@ -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 },
+18
View File
@@ -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<SyncOptions> {
// 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 (
+1 -1
View File
@@ -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", () => {