From 83d6cd03962270ea2929df641331b78eede7bb27 Mon Sep 17 00:00:00 2001 From: Kelvin Schoofs Date: Thu, 11 Feb 2021 16:34:21 +0100 Subject: [PATCH] Add flag system with "sshfs.flags" config option --- package.json | 7 +++++++ src/config.ts | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/package.json b/package.json index 688ebaa..4dc2ec6 100644 --- a/package.json +++ b/package.json @@ -290,6 +290,13 @@ "password": "CorrectHorseBatteryStaple" } ] + }, + "sshfs.flags": { + "title": "List of special flags to enable/disable certain fixes/features", + "description": "Flags are usually used for issues or beta testing. Flags can disappear/change anytime!", + "type": "array", + "items": "string", + "default": [] } } }, diff --git a/src/config.ts b/src/config.ts index ee26246..55cf882 100644 --- a/src/config.ts +++ b/src/config.ts @@ -326,3 +326,28 @@ vscode.workspace.onDidChangeConfiguration(async (e) => { return loadConfigs(); }); loadConfigs(); + +/** + * Checks the `sshfs.flags` config (overridable by e.g. workspace settings). + * - Flags are case-insensitive + * - If a flag appears twice, the first mention of it is used + * - If a flag appears as "NAME", `null` is returned + * - If a flag appears as "FLAG=VALUE", `VALUE` is returned as a string + * - If a flag is missing, `undefined` is returned (different from `null`!) + * @param target The name of the flag to look for + */ +export function getFlag(target: string): string | null | undefined { + target = target.toLowerCase(); + const flags: string[] = vscode.workspace.getConfiguration('sshfs').get('flags') || []; + for (const flag of flags) { + let name: string = flag; + let value: any = null; + const eq = flag.indexOf('='); + if (eq !== -1) { + name = flag.substring(0, eq); + value = flag.substring(eq + 1); + } + if (name.toLowerCase() === target) return value; + } + return undefined; +}