diff --git a/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js b/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js index ecf607db1ca..458ab73d945 100755 --- a/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js +++ b/javascriptv3/example_code/cross-services/wkflw-resilient-service/index.js @@ -42,5 +42,10 @@ export const scenarios = { import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { - parseScenarioArgs(scenarios); + parseScenarioArgs(scenarios, { + name: "Resilient Workflow", + synopsis: + "node index.js --scenario [-h|--help] [-y|--yes] [-v|--verbose]", + description: "Deploy and interact with scalable EC2 instances.", + }); } diff --git a/javascriptv3/example_code/libs/scenario/scenario-parser.js b/javascriptv3/example_code/libs/scenario/scenario-parser.js index 917b5bcb207..bd1825a973b 100644 --- a/javascriptv3/example_code/libs/scenario/scenario-parser.js +++ b/javascriptv3/example_code/libs/scenario/scenario-parser.js @@ -2,74 +2,67 @@ // SPDX-License-Identifier: Apache-2.0 import { parseArgs } from "node:util"; +import { printManPage } from "../utils/util-node.js"; +import { logger } from "../utils/util-log.js"; /** * @param {Record} scenarios + * @param {{name: string, synopsis: string, description: string}} [info] - High level info describing the suite of scenarios. */ -export function parseScenarioArgs(scenarios) { - const help = `Usage: -node . -s <${Object.keys(scenarios).join("|")}> -node . -h - -Options: -[-s|--scenario, ] [-h|--help] [-y|--yes] [-v|--verbose] - --h, --help Show this help message. --s, --scenario The name of a scenario to run. --y, --yes Assume "yes" to all prompts. --v, --verbose Show debug information. -`; - - const { values } = parseArgs({ - options: { - help: { - type: "boolean", - short: "h", - }, - scenario: { - short: "s", - type: "string", - }, - yes: { - short: "y", - type: "boolean", - }, - verbose: { - short: "v", - type: "boolean", - }, +export const parseScenarioArgs = ( + scenarios, + { name = "", synopsis = "", description = "" } = {}, +) => { + const options = { + help: { + type: "boolean", + short: "h", }, - }); + scenario: { + short: "s", + type: "string", + }, + yes: { + short: "y", + type: "boolean", + }, + verbose: { + short: "v", + type: "boolean", + }, + }; + + const { values } = parseArgs({ options }); + const helpPage = () => { + printManPage(options, { + name, + synopsis: synopsis ?? `node . -s <${Object.keys(scenarios).join("|")}>`, + description, + }); + }; if (values.help) { - console.log(help); + helpPage(); return; } if (!values.scenario) { - console.log(`Missing required argument: -s, --scenario\n\n${help}`); + logger.error("Missing required argument: -s, --scenario"); + helpPage(); return; } if (!(values.scenario in scenarios)) { - throw new Error(`Invalid scenario: ${values.scenario}\n${help}`); + logger.error(`Invalid scenario: ${values.scenario}`); } if (values.verbose) { - console.log( - `[DEBUG ${new Date().toISOString()}] Running scenario: ${ - scenarios[values.scenario].name - }`, - ); - console.log( - `[DEBUG ${new Date().toISOString()}] State: ${JSON.stringify( - scenarios[values.scenario].state, - )}`, - ); + logger.debug(`Running scenario: ${scenarios[values.scenario].name}`); + logger.debug(`State: ${JSON.stringify(scenarios[values.scenario].state)}`); } return scenarios[values.scenario].run({ confirmAll: values.yes, verbose: values.verbose, }); -} +}; diff --git a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js index 7903a30c2d2..76a2bc0cb94 100644 --- a/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js +++ b/javascriptv3/example_code/medical-imaging/scenarios/health-image-sets/index.js @@ -97,5 +97,11 @@ const scenarios = { // Call function if run directly import { fileURLToPath } from "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { - parseScenarioArgs(scenarios); + parseScenarioArgs(scenarios, { + name: "Health Imaging Workflow", + description: + "Work with DICOM images using an AWS Health Imaging data store.", + synopsis: + "node index.js --scenario [-h|--help] [-y|--yes] [-v|--verbose]", + }); } diff --git a/javascriptv3/example_code/s3/scenarios/object-locking/index.js b/javascriptv3/example_code/s3/scenarios/object-locking/index.js index 8466920417d..9842162f7f1 100644 --- a/javascriptv3/example_code/s3/scenarios/object-locking/index.js +++ b/javascriptv3/example_code/s3/scenarios/object-locking/index.js @@ -101,5 +101,11 @@ import { replAction } from "./repl.steps.js"; if (process.argv[1] === fileURLToPath(import.meta.url)) { const objectLockingScenarios = getWorkflowStages(Scenarios); - Scenarios.parseScenarioArgs(objectLockingScenarios); + Scenarios.parseScenarioArgs(objectLockingScenarios, { + name: "Amazon S3 object locking workflow", + description: + "Work with Amazon Simple Storage Service (Amazon S3) object locking features.", + synopsis: + "node index.js --scenario [-h|--help] [-y|--yes] [-v|--verbose]", + }); }