Commit 07d134b

Keith Broughton <keith.broughton@luxuryescapes.com>
2021-08-10 12:43:03
Fix CLI options such as --quiet (#168)
Co-authored-by: Anton Medvedev <antonmedv@google.com>
1 parent 9725997
Changed files (2)
test.mjs
@@ -92,6 +92,11 @@ import path from 'path'
   await $`node zx.mjs examples/typescript.ts`
 }
 
+{ // Quiet mode is working
+  let {stdout} = await $`node zx.mjs --quiet examples/markdown.md`
+  assert(!stdout.includes('whoami'))
+}
+
 { // Pipes are working
   let {stdout} = await $`echo "hello"`
     .pipe($`awk '{print $1" world"}'`)
zx.mjs
@@ -26,8 +26,8 @@ try {
     console.log(`zx version ${createRequire(import.meta.url)('./package.json').version}`)
     process.exit(0)
   }
-  let firstArg = process.argv[2]
-  if (typeof firstArg === 'undefined' || firstArg[0] === '-') {
+  let firstArg = process.argv.slice(2).find(a => !a.startsWith('--'));
+  if (typeof firstArg === 'undefined' || firstArg === '-') {
     let ok = await scriptFromStdin()
     if (!ok) {
       printUsage()