From abb649023209a8b05ff89ba94ce474744d5c79f0 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Tue, 12 Nov 2024 13:27:58 +0530 Subject: [PATCH 1/4] feat: add option to omit headers in CLI run command output --- packages/bruno-cli/src/commands/run.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 58b3cdf803..feb912e0f8 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -259,10 +259,17 @@ const builder = async (yargs) => { type: 'boolean', description: 'Stop execution after a failure of a request, test, or assertion' }) + .option('omit-headers', { + type: 'boolean', + description: 'Omit headers in the output', + default: false + }) + .example('$0 run request.bru', 'Run a request') .example('$0 run request.bru --env local', 'Run a request with the environment set to local') .example('$0 run folder', 'Run all requests in a folder') .example('$0 run folder -r', 'Run all requests in a folder recursively') + .example('$0 run --omit-headers', 'Run all requests in a folder recursively with omitted headers in the output') .example( '$0 run request.bru --env local --env-var secret=xxx', 'Run a request with the environment set to local and overwrite the variable secret with value xxx' @@ -312,7 +319,8 @@ const handler = async function (argv) { reporterHtml, sandbox, testsOnly, - bail + bail, + omitHeaders } = argv; const collectionPath = process.cwd(); @@ -524,6 +532,12 @@ const handler = async function (argv) { runtime: process.hrtime(start)[0] + process.hrtime(start)[1] / 1e9, suitename: bruFilepath.replace('.bru', '') }); + if (omitHeaders) { + results.forEach((result) => { + result.request.headers = {}; + result.response.headers = {}; + }); + } // bail if option is set and there is a failure if (bail) { From 45cc97ee20a5d9fe451a4204eb7b200b090509b6 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Wed, 13 Nov 2024 14:51:48 +0530 Subject: [PATCH 2/4] feat: add option to skip specific headers in CLI run command output --- packages/bruno-cli/src/commands/run.js | 35 +++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index feb912e0f8..a07a1f98ed 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -264,12 +264,21 @@ const builder = async (yargs) => { description: 'Omit headers in the output', default: false }) + .option('skip-headers', { + type: 'array', + description: 'Skip specific headers in the output', + default: [] + }) .example('$0 run request.bru', 'Run a request') .example('$0 run request.bru --env local', 'Run a request with the environment set to local') .example('$0 run folder', 'Run all requests in a folder') .example('$0 run folder -r', 'Run all requests in a folder recursively') .example('$0 run --omit-headers', 'Run all requests in a folder recursively with omitted headers in the output') + .example( + '$0 run --skip-headers "Authorization"', + 'Run all requests in a folder recursively with skipped headers in the output' + ) .example( '$0 run request.bru --env local --env-var secret=xxx', 'Run a request with the environment set to local and overwrite the variable secret with value xxx' @@ -320,7 +329,8 @@ const handler = async function (argv) { sandbox, testsOnly, bail, - omitHeaders + omitHeaders, + skipHeaders } = argv; const collectionPath = process.cwd(); @@ -532,6 +542,7 @@ const handler = async function (argv) { runtime: process.hrtime(start)[0] + process.hrtime(start)[1] / 1e9, suitename: bruFilepath.replace('.bru', '') }); + if (omitHeaders) { results.forEach((result) => { result.request.headers = {}; @@ -539,6 +550,28 @@ const handler = async function (argv) { }); } + const deleteHeaderIfExists = (headers, header) => { + if (headers && headers[header]) { + delete headers[header]; + } + }; + + if (skipHeaders?.length) { + results.forEach((result) => { + if (result.request?.headers) { + skipHeaders.forEach((header) => { + deleteHeaderIfExists(result.request.headers, header); + }); + } + if (result.response?.headers) { + skipHeaders.forEach((header) => { + deleteHeaderIfExists(result.response.headers, header); + }); + } + }); + } + + // bail if option is set and there is a failure if (bail) { const requestFailure = result?.error; From 72bd1b4cbf0b0577aee535891911a1fa72cbfc56 Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Thu, 21 Nov 2024 15:36:15 +0530 Subject: [PATCH 3/4] feat: rename CLI options for omitting and skipping headers to clarify reporter context --- packages/bruno-cli/src/commands/run.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index a07a1f98ed..2b7dc96b2d 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -259,14 +259,14 @@ const builder = async (yargs) => { type: 'boolean', description: 'Stop execution after a failure of a request, test, or assertion' }) - .option('omit-headers', { + .option('reporter-omit-headers', { type: 'boolean', - description: 'Omit headers in the output', + description: 'Omit headers from the reporter output', default: false }) - .option('skip-headers', { + .option('reporter-skip-headers', { type: 'array', - description: 'Skip specific headers in the output', + description: 'Skip specific headers from the reporter output', default: [] }) @@ -274,10 +274,10 @@ const builder = async (yargs) => { .example('$0 run request.bru --env local', 'Run a request with the environment set to local') .example('$0 run folder', 'Run all requests in a folder') .example('$0 run folder -r', 'Run all requests in a folder recursively') - .example('$0 run --omit-headers', 'Run all requests in a folder recursively with omitted headers in the output') + .example('$0 run --reporter-omit-headers', 'Run all requests in a folder recursively with omitted headers from the reporter output') .example( - '$0 run --skip-headers "Authorization"', - 'Run all requests in a folder recursively with skipped headers in the output' + '$0 run --reporter-skip-headers "Authorization"', + 'Run all requests in a folder recursively with skipped headers from the reporter output' ) .example( '$0 run request.bru --env local --env-var secret=xxx', @@ -329,8 +329,8 @@ const handler = async function (argv) { sandbox, testsOnly, bail, - omitHeaders, - skipHeaders + reporterOmitHeaders, + reporterSkipHeaders } = argv; const collectionPath = process.cwd(); @@ -543,7 +543,7 @@ const handler = async function (argv) { suitename: bruFilepath.replace('.bru', '') }); - if (omitHeaders) { + if (reporterOmitHeaders) { results.forEach((result) => { result.request.headers = {}; result.response.headers = {}; @@ -556,15 +556,15 @@ const handler = async function (argv) { } }; - if (skipHeaders?.length) { + if (reporterSkipHeaders?.length) { results.forEach((result) => { if (result.request?.headers) { - skipHeaders.forEach((header) => { + reporterSkipHeaders.forEach((header) => { deleteHeaderIfExists(result.request.headers, header); }); } if (result.response?.headers) { - skipHeaders.forEach((header) => { + reporterSkipHeaders.forEach((header) => { deleteHeaderIfExists(result.response.headers, header); }); } From 157389424d17670ac39fc38a7252eebf7d9118ad Mon Sep 17 00:00:00 2001 From: Pragadesh-45 Date: Thu, 21 Nov 2024 16:28:28 +0530 Subject: [PATCH 4/4] feat: rename CLI option for omitting headers to clarify functionality --- packages/bruno-cli/src/commands/run.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/bruno-cli/src/commands/run.js b/packages/bruno-cli/src/commands/run.js index 2b7dc96b2d..4f0c48d30f 100644 --- a/packages/bruno-cli/src/commands/run.js +++ b/packages/bruno-cli/src/commands/run.js @@ -259,7 +259,7 @@ const builder = async (yargs) => { type: 'boolean', description: 'Stop execution after a failure of a request, test, or assertion' }) - .option('reporter-omit-headers', { + .option('reporter-skip-all-headers', { type: 'boolean', description: 'Omit headers from the reporter output', default: false @@ -274,7 +274,7 @@ const builder = async (yargs) => { .example('$0 run request.bru --env local', 'Run a request with the environment set to local') .example('$0 run folder', 'Run all requests in a folder') .example('$0 run folder -r', 'Run all requests in a folder recursively') - .example('$0 run --reporter-omit-headers', 'Run all requests in a folder recursively with omitted headers from the reporter output') + .example('$0 run --reporter-skip-all-headers', 'Run all requests in a folder recursively with omitted headers from the reporter output') .example( '$0 run --reporter-skip-headers "Authorization"', 'Run all requests in a folder recursively with skipped headers from the reporter output' @@ -329,7 +329,7 @@ const handler = async function (argv) { sandbox, testsOnly, bail, - reporterOmitHeaders, + reporterSkipAllHeaders, reporterSkipHeaders } = argv; const collectionPath = process.cwd(); @@ -543,7 +543,7 @@ const handler = async function (argv) { suitename: bruFilepath.replace('.bru', '') }); - if (reporterOmitHeaders) { + if (reporterSkipAllHeaders) { results.forEach((result) => { result.request.headers = {}; result.response.headers = {};