Skip to content

Commit

Permalink
feat: add $.silent
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 31, 2021
1 parent 937a6a2 commit e833960
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ npm i zx-extra
```

## Usage
### ``$.noquote`command` ``
Runs target cmd with disabled `shq`.
### ``$.raw`command` ``
Evaluates target cmd as is with disabled `shq`.
```js
const cmd = 'echo foo'
const msg = 'bar'
const output = (await $.noquote`${cmd} ${msg}`).toString().trim()
const output = (await $.raw`${cmd} ${msg}`).toString().trim()
// $ echo foo bar
```

### ``$.silent`command` ``
Sets `verbose = false` for once invocation.
```js
await $.silent`echo foo`
// <no output in console>
```

6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * from 'zx'

interface $ {
raw: $
silent: $
}
11 changes: 10 additions & 1 deletion index.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import {$} from 'zx'

$.noquote = async (...args) => {
$.raw = async (...args) => {
const q = $.quote
$.quote = v => v
const p = $(...args)
await p
$.quote = q
return p
}

$.silent = async (...args) => {
const v = $.verbose
$.verbose = false
const p = $(...args)
await p
$.verbose = v
return p
}
8 changes: 7 additions & 1 deletion test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import {strict as assert} from 'assert'

// $.raw
{
const cmd = 'echo foo'
const msg = 'bar'
const output = (await $.noquote`${cmd} ${msg}`).toString().trim()
const output = (await $.raw`${cmd} ${msg}`).toString().trim()
assert(output === 'foo bar')
}

// $.silent
{
await $.silent`echo foo`
}

0 comments on commit e833960

Please sign in to comment.