Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "verbose" option #532

Merged
merged 3 commits into from Mar 6, 2023
Merged

Add "verbose" option #532

merged 3 commits into from Mar 6, 2023

Conversation

ehmicky
Copy link
Collaborator

@ehmicky ehmicky commented Mar 5, 2023

Fixes #524.

This adds a verbose boolean option. It defaults to false, unless the NODE_DEBUG=execa environment variable is set. When enabled, it prints any command before executing it. It also prints a timestamp.

The "problem" and "prior art" sections in #524 give some background on why this feature might be a good addition.

For example, the following script:

import {$} from 'execa'

await $`echo one`
await $`echo two`

Would print:

$ node example.js

$ NODE_DEBUG=execa node example.js
[22:44:57.723] echo one
[22:44:57.731] echo two

While the following:

import {$} from 'execa'

const $$ = $({ stdio: 'inherit' })

await $$`echo one`
await $$`echo two`

Would print:

$ node example.js
one
two

$ NODE_DEBUG=execa node example.js
[22:47:52.056] echo one
one
[22:47:52.060] echo two
two

This can also be enabled for individual commands with:

await $({ verbose: true })`echo one`

This feature works with any other Execa method too.

await execa('echo', ['one'], { verbose: true })

The PR's code and tests are done, but I haven't added the types, type tests nor readme documentation. I'd like to first confirm the overall idea and design make sense to you @sindresorhus. :)

lib/verbose.js Show resolved Hide resolved
lib/verbose.js Show resolved Hide resolved
@sindresorhus
Copy link
Owner

This looks good to me. Carry on.

@ehmicky
Copy link
Collaborator Author

ehmicky commented Mar 6, 2023

This is now documented and typed, ready to review 👍

@sindresorhus sindresorhus merged commit 69ce814 into main Mar 6, 2023
16 of 18 checks passed
@sindresorhus sindresorhus deleted the verbose branch March 6, 2023 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Verbose mode
2 participants