]> git.ardis.lu - transcriber/commitdiff
Add --show-command option to make logging the command optional
authorArdis Lu <ardisglu@gmail.com>
Thu, 19 Sep 2024 04:11:05 +0000 (21:11 -0700)
committerArdis Lu <ardisglu@gmail.com>
Thu, 19 Sep 2024 04:11:05 +0000 (21:11 -0700)
README.md
index.ts

index 33c199a00c90c6b344e29d89e711a9f0d250e4f2..abf72571b696bbfcd9be5b93ac0100bebba6ac46 100644 (file)
--- 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.
index 1d8b4bb6b45b45e83489e74970163e99e81459fe..9f9759dce2ed000186625cc8eb16cf2171068d16 100644 (file)
--- a/index.ts
+++ b/index.ts
@@ -9,9 +9,13 @@ const program = new Command()
     "-i, --input <string>",
     "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("-------");
This page took 0.043867 seconds and 4 git commands to generate.