From fc2ea13a6727096f0a3cc1c804bd387e86e6c749 Mon Sep 17 00:00:00 2001 From: Volodymyr Kolesnykov Date: Fri, 19 Jan 2024 09:44:41 +0200 Subject: [PATCH] fix(dev-env): always lowercase environment slug --- src/bin/vip-dev-env-create.js | 3 ++- src/bin/vip-dev-env-destroy.js | 3 ++- src/bin/vip-dev-env-exec.js | 3 ++- src/bin/vip-dev-env-import-media.js | 3 ++- src/bin/vip-dev-env-import-sql.js | 3 ++- src/bin/vip-dev-env-info.js | 3 ++- src/bin/vip-dev-env-logs.js | 3 ++- src/bin/vip-dev-env-shell.js | 3 ++- src/bin/vip-dev-env-start.js | 3 ++- src/bin/vip-dev-env-stop.js | 3 ++- src/bin/vip-dev-env-sync-sql.js | 3 ++- src/bin/vip-dev-env-update.js | 8 +++++++- src/lib/dev-environment/dev-environment-cli.ts | 5 +++++ 13 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/bin/vip-dev-env-create.js b/src/bin/vip-dev-env-create.js index 772b3fd93..695c06b76 100755 --- a/src/bin/vip-dev-env-create.js +++ b/src/bin/vip-dev-env-create.js @@ -20,6 +20,7 @@ import { validateDependencies, processStringOrBooleanOption, handleDeprecatedOptions, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { getConfigurationFileOptions, @@ -69,7 +70,7 @@ const examples = [ ]; const cmd = command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'title', 'Title for the WordPress site' ) .option( 'multisite', 'Enable multisite install', undefined, processStringOrBooleanOption ); diff --git a/src/bin/vip-dev-env-destroy.js b/src/bin/vip-dev-env-destroy.js index 9a97c3789..2ae1baec5 100755 --- a/src/bin/vip-dev-env-destroy.js +++ b/src/bin/vip-dev-env-destroy.js @@ -9,6 +9,7 @@ import { getEnvTrackingInfo, getEnvironmentName, handleCLIException, + processSlug, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; import { destroyEnvironment } from '../lib/dev-environment/dev-environment-core'; @@ -29,7 +30,7 @@ const examples = [ ]; command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'soft', 'Keep config files needed to start an environment intact' ) .examples( examples ) .argv( process.argv, async ( arg, opt ) => { diff --git a/src/bin/vip-dev-env-exec.js b/src/bin/vip-dev-env-exec.js index 120be16c6..03e3b16aa 100755 --- a/src/bin/vip-dev-env-exec.js +++ b/src/bin/vip-dev-env-exec.js @@ -7,6 +7,7 @@ import { getEnvironmentName, handleCLIException, processBooleanOption, + processSlug, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; import { exec, getEnvironmentPath } from '../lib/dev-environment/dev-environment-core'; @@ -30,7 +31,7 @@ const examples = [ ]; command( { wildcardCommand: true } ) - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'force', 'Disable validations before task execution', undefined, processBooleanOption ) .option( 'quiet', 'Suppress output', undefined, processBooleanOption ) .examples( examples ) diff --git a/src/bin/vip-dev-env-import-media.js b/src/bin/vip-dev-env-import-media.js index e06d19424..933145617 100755 --- a/src/bin/vip-dev-env-import-media.js +++ b/src/bin/vip-dev-env-import-media.js @@ -6,6 +6,7 @@ import { getEnvironmentName, getEnvTrackingInfo, handleCLIException, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { importMediaPath } from '../lib/dev-environment/dev-environment-core'; import { trackEvent } from '../lib/tracker'; @@ -27,7 +28,7 @@ command( { requiredArgs: 1, } ) .examples( examples ) - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .argv( process.argv, async ( unmatchedArgs, opt ) => { const [ filePath ] = unmatchedArgs; const slug = await getEnvironmentName( opt ); diff --git a/src/bin/vip-dev-env-import-sql.js b/src/bin/vip-dev-env-import-sql.js index 5efdc86c6..c4215c8b1 100755 --- a/src/bin/vip-dev-env-import-sql.js +++ b/src/bin/vip-dev-env-import-sql.js @@ -7,6 +7,7 @@ import { getEnvTrackingInfo, handleCLIException, getEnvironmentName, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { makeCommandTracker } from '../lib/tracker'; @@ -34,7 +35,7 @@ const examples = [ command( { requiredArgs: 1, } ) - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( [ 'r', 'search-replace' ], 'Perform Search and Replace on the specified SQL file' ) .option( 'in-place', 'Search and Replace explicitly on the given input file' ) .option( 'skip-validate', 'Do not perform file validation' ) diff --git a/src/bin/vip-dev-env-info.js b/src/bin/vip-dev-env-info.js index 685830784..58edf3953 100755 --- a/src/bin/vip-dev-env-info.js +++ b/src/bin/vip-dev-env-info.js @@ -8,6 +8,7 @@ import { getEnvTrackingInfo, getEnvironmentName, handleCLIException, + processSlug, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; import { @@ -31,7 +32,7 @@ const examples = [ ]; command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'all', 'Show Info for all local dev environments' ) .option( 'extended', 'Show extended information about the dev environment' ) .examples( examples ) diff --git a/src/bin/vip-dev-env-logs.js b/src/bin/vip-dev-env-logs.js index 9ccb04f4d..696f9e5f8 100755 --- a/src/bin/vip-dev-env-logs.js +++ b/src/bin/vip-dev-env-logs.js @@ -8,6 +8,7 @@ import { getEnvTrackingInfo, getEnvironmentName, handleCLIException, + processSlug, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; import { showLogs } from '../lib/dev-environment/dev-environment-core'; @@ -34,7 +35,7 @@ const examples = [ ]; command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( [ 'f', 'follow' ], 'Follow logs for a specific service in local dev environment' ) .option( 'service', diff --git a/src/bin/vip-dev-env-shell.js b/src/bin/vip-dev-env-shell.js index e2832a90c..e8c420287 100755 --- a/src/bin/vip-dev-env-shell.js +++ b/src/bin/vip-dev-env-shell.js @@ -9,6 +9,7 @@ import { validateDependencies, getEnvironmentName, handleCLIException, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { getEnvironmentPath } from '../lib/dev-environment/dev-environment-core'; import { bootstrapLando, landoShell } from '../lib/dev-environment/dev-environment-lando'; @@ -70,7 +71,7 @@ function getCommand( args ) { } command( { wildcardCommand: true } ) - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'root', 'Spawn a root shell' ) .option( 'service', 'Spawn a shell in a specific service (php if omitted)' ) .examples( examples ) diff --git a/src/bin/vip-dev-env-start.js b/src/bin/vip-dev-env-start.js index 4fb9a4052..94da10981 100755 --- a/src/bin/vip-dev-env-start.js +++ b/src/bin/vip-dev-env-start.js @@ -10,6 +10,7 @@ import { getEnvironmentName, handleCLIException, postStart, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { startEnvironment } from '../lib/dev-environment/dev-environment-core'; import { bootstrapLando } from '../lib/dev-environment/dev-environment-lando'; @@ -30,7 +31,7 @@ const examples = [ ]; command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'skip-rebuild', 'Only start stopped services' ) .option( [ 'w', 'skip-wp-versions-check' ], diff --git a/src/bin/vip-dev-env-stop.js b/src/bin/vip-dev-env-stop.js index 587e60909..6e97bde59 100755 --- a/src/bin/vip-dev-env-stop.js +++ b/src/bin/vip-dev-env-stop.js @@ -9,6 +9,7 @@ import { getEnvTrackingInfo, getEnvironmentName, handleCLIException, + processSlug, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; import { stopEnvironment } from '../lib/dev-environment/dev-environment-core'; @@ -25,7 +26,7 @@ const examples = [ ]; command() - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .examples( examples ) .argv( process.argv, async ( arg, opt ) => { const slug = await getEnvironmentName( opt ); diff --git a/src/bin/vip-dev-env-sync-sql.js b/src/bin/vip-dev-env-sync-sql.js index 6e00a674d..a4f74e963 100755 --- a/src/bin/vip-dev-env-sync-sql.js +++ b/src/bin/vip-dev-env-sync-sql.js @@ -6,6 +6,7 @@ import { DEV_ENVIRONMENT_FULL_COMMAND } from '../lib/constants/dev-environment'; import { getEnvironmentName, processBooleanOption, + processSlug, } from '../lib/dev-environment/dev-environment-cli'; import { getEnvironmentPath } from '../lib/dev-environment/dev-environment-core'; import { bootstrapLando, isEnvUp } from '../lib/dev-environment/dev-environment-lando'; @@ -49,7 +50,7 @@ command( { requiredArgs: 0, module: 'dev-env-sync-sql', } ) - .option( 'slug', 'Custom name of the dev environment' ) + .option( 'slug', 'Custom name of the dev environment', undefined, processSlug ) .option( 'force', 'Disable validations before running sync', undefined, processBooleanOption ) .examples( examples ) .argv( process.argv, async ( arg, opt ) => { diff --git a/src/bin/vip-dev-env-update.js b/src/bin/vip-dev-env-update.js index 501c16a46..65fedaa70 100755 --- a/src/bin/vip-dev-env-update.js +++ b/src/bin/vip-dev-env-update.js @@ -15,6 +15,7 @@ import { getEnvironmentName, handleCLIException, handleDeprecatedOptions, + processSlug, promptForArguments, validateDependencies, } from '../lib/dev-environment/dev-environment-cli'; @@ -39,7 +40,12 @@ const examples = [ description: 'Retriggers setup wizard in order to change environment configuration', }, ]; -const cmd = command().option( 'slug', 'Custom name of the dev environment' ); +const cmd = command().option( + 'slug', + 'Custom name of the dev environment', + undefined, + processSlug +); addDevEnvConfigurationOptions( cmd ); diff --git a/src/lib/dev-environment/dev-environment-cli.ts b/src/lib/dev-environment/dev-environment-cli.ts index 655721bae..481081e3a 100644 --- a/src/lib/dev-environment/dev-environment-cli.ts +++ b/src/lib/dev-environment/dev-environment-cli.ts @@ -837,6 +837,11 @@ export function processStringOrBooleanOption( value: string | boolean ): string return value; } +export function processSlug( value: unknown ): string { + // eslint-disable-next-line @typescript-eslint/no-base-to-string + return ( value ?? '' ).toString().toLowerCase(); +} + declare function isNaN( value: unknown ): boolean; declare function parseFloat( value: unknown ): number;