Skip to content

Commit

Permalink
feat: add ProcessPromise .verbose() for symmetry with.quiet()
Browse files Browse the repository at this point in the history
relates google#710
  • Loading branch information
antongolub committed May 23, 2024
1 parent 8be10e0 commit fa1f14d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
private _stdio?: StdioOptions
private _nothrow?: boolean
private _quiet?: boolean
private _verbose?: boolean
private _timeout?: number
private _timeoutSignal = 'SIGTERM'
private _resolved = false
Expand Down Expand Up @@ -487,8 +488,13 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this
}

quiet(): ProcessPromise {
this._quiet = true
quiet(v = true): ProcessPromise {
this._quiet = v
return this
}

verbose(v = true): ProcessPromise {
this._verbose = v
return this
}

Expand All @@ -497,7 +503,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
}

isVerbose(): boolean {
return this._snapshot.verbose && !this.isQuiet()
return (this._verbose ?? this._snapshot.verbose) && !this.isQuiet()
}

timeout(d: Duration, signal = 'SIGTERM'): ProcessPromise {
Expand Down
11 changes: 11 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ describe('core', () => {
}
})

test('verbose() mode is working', async () => {
const p = $`echo 'test'`
assert.equal(p.isVerbose(), false)

p.verbose()
assert.equal(p.isVerbose(), true)

p.verbose(false)
assert.equal(p.isVerbose(), false)
})

test('nothrow() do not throw', async () => {
let { exitCode } = await $`exit 42`.nothrow()
assert.equal(exitCode, 42)
Expand Down

0 comments on commit fa1f14d

Please sign in to comment.