Skip to content

Commit

Permalink
fix(dev-env): always lowercase environment slug
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Jan 19, 2024
1 parent 4882d4a commit f68eeb0
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-create.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
validateDependencies,
processStringOrBooleanOption,
handleDeprecatedOptions,
processSlug,
} from '../lib/dev-environment/dev-environment-cli';
import {
getConfigurationFileOptions,
Expand Down Expand Up @@ -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 );

Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 ) => {
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-import-media.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getEnvTrackingInfo,
handleCLIException,
getEnvironmentName,
processSlug,
} from '../lib/dev-environment/dev-environment-cli';
import { makeCommandTracker } from '../lib/tracker';

Expand Down Expand Up @@ -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' )
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
getEnvTrackingInfo,
getEnvironmentName,
handleCLIException,
processSlug,
validateDependencies,
} from '../lib/dev-environment/dev-environment-cli';
import {
Expand All @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 )
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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' ],
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 );
Expand Down
3 changes: 2 additions & 1 deletion src/bin/vip-dev-env-sync-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ) => {
Expand Down
8 changes: 7 additions & 1 deletion src/bin/vip-dev-env-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getEnvironmentName,
handleCLIException,
handleDeprecatedOptions,
processSlug,
promptForArguments,
validateDependencies,
} from '../lib/dev-environment/dev-environment-cli';
Expand All @@ -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 );

Expand Down
5 changes: 5 additions & 0 deletions src/lib/dev-environment/dev-environment-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit f68eeb0

Please sign in to comment.