From e9a74ed2ca80499350592163c0a50948cd372801 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 18 Sep 2024 21:11:05 -0700 Subject: [PATCH] Add --show-command option to make logging the command optional --- README.md | 45 ++++++++++++++++++++++++++++++--------------- index.ts | 14 +++++++++++--- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 33c199a..abf7257 100644 --- a/README.md +++ b/README.md @@ -27,29 +27,44 @@ Do: ```plaintext bun run index.ts -- --input ./examples/echo.json -$ echo value1 value3 value5 value1 value3 value5 - -$ echo value1 value3 value6 value1 value3 value6 - -$ echo value1 value4 value5 value1 value4 value5 - -$ echo value1 value4 value6 value1 value4 value6 - -$ echo value2 value3 value5 value2 value3 value5 - -$ echo value2 value3 value6 value2 value3 value6 - -$ echo value2 value4 value5 value2 value4 value5 - -$ echo value2 value4 value6 value2 value4 value6 ``` +Pass `--show-command` and/or `--show-args` to log the command and/or args specified in the input JSON: + +```plaintext +bun run index.ts -- --input ./examples/echo.json --show-command --show-args + +$ echo value1 value3 value5 +┌──────┬────────┐ +│ │ Values │ +├──────┼────────┤ +│ arg1 │ value1 │ +│ arg2 │ value3 │ +│ arg3 │ value5 │ +└──────┴────────┘ +------- +value1 value3 value5 + +$ echo value1 value3 value6 +┌──────┬────────┐ +│ │ Values │ +├──────┼────────┤ +│ arg1 │ value1 │ +│ arg2 │ value3 │ +│ arg3 │ value6 │ +└──────┴────────┘ +------- +value1 value3 value6 + +[...] +``` + More examples can be found within the [**`/examples`**](./examples) folder. diff --git a/index.ts b/index.ts index 1d8b4bb..9f9759d 100644 --- a/index.ts +++ b/index.ts @@ -9,9 +9,13 @@ const program = new Command() "-i, --input ", "JSON file with command and arguments to execute", ) + .option( + "--show-command", + "log input command", + ) .option( "--show-args", - "log input arguments along with the input command", + "log input arguments", ); program.parse(); const options = program.opts(); @@ -49,7 +53,9 @@ const c = Object.defineProperty([command], "raw", { }) as unknown as TemplateStringsArray; if (args === undefined) { - console.log(`\n$ ${command}`); + if (options.showCommand) { + console.log(`\n$ ${command}`); + } await $(c); } else { const runs = getCombinations(args); @@ -58,7 +64,9 @@ if (args === undefined) { for (const [key, value] of Object.entries(inputArgs)) { input = input.replaceAll(`$${key}`, value); } - console.log(`\n$ ${input}`); + if (options.showCommand) { + console.log(`\n$ ${input}`); + } if (options.showArgs) { console.table(inputArgs); console.log("-------"); -- 2.47.3