From 01f5906a4904d87a2db82f59599b43d080dff802 Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Mon, 28 Feb 2022 14:10:20 +0700 Subject: [PATCH 1/2] feat(exec): Allow listing of scripts when - no script name provided - --list flag is passed --- packages/cli/src/commands/exec.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/cli/src/commands/exec.js b/packages/cli/src/commands/exec.js index f5a3b88f83a3..7cb92eebfd09 100644 --- a/packages/cli/src/commands/exec.js +++ b/packages/cli/src/commands/exec.js @@ -28,7 +28,7 @@ const runScript = async (scriptPath, scriptArgs) => { return } -export const command = 'exec ' +export const command = 'exec [name]' export const description = 'Run scripts generated with yarn generate script' export const builder = (yargs) => { yargs @@ -41,6 +41,12 @@ export const builder = (yargs) => { default: true, description: 'Generate the Prisma client', }) + .option('list', { + alias: 'ls', + type: 'boolean', + default: false, + description: 'List available scripts', + }) .strict(false) .epilogue( `Also see the ${terminalLink( @@ -50,8 +56,22 @@ export const builder = (yargs) => { ) } +const printAvailableScriptsToConsole = () => { + console.log('Available scripts:') + findScripts().forEach((scriptPath) => { + const { name } = path.parse(scriptPath) + console.log(c.info(`- ${name}`)) + }) + console.log() +} + export const handler = async (args) => { - const { name, prisma, ...scriptArgs } = args + const { name, prisma, list, ...scriptArgs } = args + if (list || !name) { + printAvailableScriptsToConsole() + return + } + const scriptPath = path.join(getPaths().scripts, name) const { @@ -120,12 +140,7 @@ export const handler = async (args) => { c.error(`\nNo script called ${c.underline(name)} in ./scripts folder.\n`) ) - console.log('Available scripts:') - findScripts().forEach((scriptPath) => { - const { name } = path.parse(scriptPath) - console.log(c.info(`- ${name}`)) - }) - console.log() + printAvailableScriptsToConsole() process.exit(1) } From 6a2d9c8772c99d4af4879fc013a493ec88ce8092 Mon Sep 17 00:00:00 2001 From: Daniel Choudhury Date: Mon, 28 Feb 2022 15:33:36 +0700 Subject: [PATCH 2/2] Switch alias to --l --- packages/cli/src/commands/exec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/exec.js b/packages/cli/src/commands/exec.js index 7cb92eebfd09..0b6e25b1309a 100644 --- a/packages/cli/src/commands/exec.js +++ b/packages/cli/src/commands/exec.js @@ -42,7 +42,7 @@ export const builder = (yargs) => { description: 'Generate the Prisma client', }) .option('list', { - alias: 'ls', + alias: 'l', type: 'boolean', default: false, description: 'List available scripts',