From 2b384656b6e844e2a19afdf5dd7b1c33689cbeb8 Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Wed, 8 Feb 2023 03:27:27 +0530 Subject: [PATCH] feat: bruno can run a collection by specifying "bru run" --- packages/bruno-cli/src/commands/run.js | 41 +++++++++++++++++++------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index a6e499b64..fb49ae55a 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -7,7 +7,7 @@ const { bruToEnvJson, getEnvVars } = require('../utils/bru'); const { rpad } = require('../utils/common'); const { bruToJson } = require('../utils/bru'); -const command = 'run '; +const command = 'run [filename]'; const desc = 'Run a request'; const printRunSummary = (assertionResults, testResults) => { @@ -38,6 +38,8 @@ const printRunSummary = (assertionResults, testResults) => { }; const getBruFilesRecursively = (dir) => { + const environmentsPath = 'environments'; + const getFilesInOrder = (dir) => { let bruJsons = []; @@ -48,7 +50,12 @@ const getBruFilesRecursively = (dir) => { const filePath = path.join(currentPath, file); const stats = fs.lstatSync(filePath); - if (stats.isDirectory()) { + // todo: we might need a ignore config inside bruno.json + if (stats.isDirectory() && + filePath !== environmentsPath && + !filePath.startsWith(".git") && + !filePath.startsWith("node_modules") + ) { traverse(filePath); } } @@ -105,25 +112,37 @@ const builder = async (yargs) => { const handler = async function (argv) { try { - const { + let { filename, env, r: recursive } = argv; - - const pathExists = await exists(filename); - if(!pathExists) { - console.error(chalk.red(`File or directory ${filename} does not exist`)); - return; - } + const collectionPath = process.cwd(); // todo // right now, bru must be run from the root of the collection // will add support in the future to run it from anywhere inside the collection - const collectionPath = process.cwd(); - const collectionVariables = {}; + const brunoJsonPath = path.join(collectionPath, 'bruno.json'); + const brunoJsonExists = await exists(brunoJsonPath); + if(!brunoJsonExists) { + console.error(chalk.red(`You can run only at the root of a collection`)); + return; + } + if(filename && filename.length) { + const pathExists = await exists(filename); + if(!pathExists) { + console.error(chalk.red(`File or directory ${filename} does not exist`)); + return; + } + } else { + filename = "./"; + recursive = true; + } + + const collectionVariables = {}; let envVars = {}; + if(env) { const envFile = path.join(collectionPath, 'environments', `${env}.bru`); const envPathExists = await exists(envFile);