Skip to content

Commit

Permalink
fix: remove interactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
sjinks committed Jan 8, 2024
1 parent 8f7a42d commit 315a963
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/commands/dev-env-import-sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import * as exit from '../lib/cli/exit';
import { getFileMeta, unzipFile } from '../lib/client-file-uploader';
import {
processBooleanOption,
promptForBoolean,
validateDependencies,
} from '../lib/dev-environment/dev-environment-cli';
import {
Expand All @@ -27,6 +26,10 @@ export class DevEnvImportSQLCommand {
this.fileName = fileName;
this.options = options;
this.slug = slug;

if ( this.options.quiet && undefined === this.options.skipReindex ) {
this.options.skipReindex = false;
}
}

async run() {
Expand Down Expand Up @@ -80,7 +83,9 @@ export class DevEnvImportSQLCommand {
}

const fd = await fs.promises.open( resolvedPath, 'r' );
const importArg = [ 'db', '--disable-auto-rehash' ];
const importArg = [ 'db', '--disable-auto-rehash' ].concat(
this.options.quiet ? '--silent' : []
);
const origIsTTY = process.stdin.isTTY;

try {
Expand All @@ -105,7 +110,7 @@ export class DevEnvImportSQLCommand {
fs.unlinkSync( resolvedPath );
}

const cacheArg = [ 'wp', 'cache', 'flush' ];
const cacheArg = [ 'wp', 'cache', 'flush' ].concat( this.options.quiet ? '--quiet' : [] );
await exec( lando, this.slug, cacheArg );

if (
Expand All @@ -114,29 +119,25 @@ export class DevEnvImportSQLCommand {
) {
try {
await exec( lando, this.slug, [ 'wp', 'cli', 'has-command', 'vip-search' ] );
const doIndex =
this.options.quiet || undefined !== this.options.skipReindex || ! process.stdin.isTTY
? true
: await promptForBoolean(
'Do you want to index data in Elasticsearch (used by Enterprise Search)?',
true
);
if ( doIndex ) {
await exec( lando, this.slug, [
'wp',
'vip-search',
'index',
'--setup',
'--network-wide',
'--skip-confirm',
] );
}
await exec( lando, this.slug, [
'wp',
'vip-search',
'index',
'--setup',
'--network-wide',
'--skip-confirm',
] );
} catch {
// Exception means they don't have vip-search enabled.
}
}

const addUserArg = [ 'wp', 'dev-env-add-admin', '--username=vipgo', '--password=password' ];
const addUserArg = [
'wp',
'dev-env-add-admin',
'--username=vipgo',
'--password=password',
].concat( this.options.quiet ? '--quiet' : [] );
await exec( lando, this.slug, addUserArg );
}
}

0 comments on commit 315a963

Please sign in to comment.