From 9ed5d3ffa085a359c13e1992bf5276e3c74c9422 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 08:52:46 +0000 Subject: [PATCH] Refactor CLI argument handling to eliminate duplication Simplified the conditional execution logic in src/index.js for handling the --benchmark and --server flags. By checking for --server first, the remaining cases (--benchmark and default) are combined into a single execution of main(), eliminating the duplicated promise chain. Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com> --- src/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index d9af4b7..6dbae48 100644 --- a/src/index.js +++ b/src/index.js @@ -119,17 +119,22 @@ async function main() { } if (require.main === module) { - // If no args, run benchmark - if (process.argv.includes('--benchmark')) { - main().then(r => { console.log('Results:', r); process.exit(0); }).catch(e => { console.error(e); process.exit(1); }); - } else if (process.argv.includes('--server')) { + if (process.argv.includes('--server')) { const PORT = process.env.PORT || 3000; app.listen(PORT, () => { console.log(`One API Gateway listening on port ${PORT}`); }); } else { - // Original behavior default: run benchmark - main().then(r => { console.log('Results:', r); process.exit(0); }).catch(e => { console.error(e); process.exit(1); }); + // Default to benchmark if no --server flag + main() + .then(r => { + console.log('Results:', r); + process.exit(0); + }) + .catch(e => { + console.error(e); + process.exit(1); + }); } }