-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
configure output #1387
Merged
shadowspawn
merged 23 commits into
tj:release/7.x
from
shadowspawn:feature/output-override
Nov 17, 2020
Merged
configure output #1387
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ebf5334
Add output configuration and use for version and errors
shadowspawn 849bbbe
Tests passing using write/writeErr
shadowspawn c295eda
Suppress test output on stderr using spyon
shadowspawn 0d82720
Accurately set help columns for stdout/stderr
shadowspawn ab1e0ce
Remove bogus file
shadowspawn 95c3153
Tidy comments
shadowspawn 9f3efe2
Only using single argument to write, simplify declaration to match
shadowspawn 6a3eadf
Add tests for configureOutput write and writeError
shadowspawn b191033
Add tests for configureOutput getColumns and getErrorColumns
shadowspawn 627f310
Add error case too
shadowspawn 02f5b44
Use configureOutput instead of jest.spyon for some tests
shadowspawn d89c918
Add configureOutput to chain tests
shadowspawn 3477e7e
Add set/get test for configureOutput
shadowspawn a0b1db7
Rename routines with symmetrical out/err
shadowspawn 015895e
Add outputError simple code
shadowspawn 2727d13
Add tests for outputError
shadowspawn bab81d0
Add JSDoc
shadowspawn 8a68060
Tweak wording
shadowspawn 2a8d1cb
First cut at TypeScript
shadowspawn 1100c47
Add TypeScript sanity check for configureOutput
shadowspawn 7c882f6
Add example for configureOutput
shadowspawn cc42309
Add configureOutput to README
shadowspawn 0ae16fb
Make example in README a little clearer
shadowspawn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// const commander = require('commander'); // (normal include) | ||
const commander = require('../'); // include commander in git clone of commander repo | ||
|
||
const program = new commander.Command(); | ||
|
||
function red(str) { | ||
return `\x1b[31m${str}\x1b[0m`; | ||
} | ||
|
||
program | ||
.configureOutput({ | ||
// Visibly override write routines as example! | ||
writeOut: (str) => process.stdout.write(`[OUT] ${str}`), | ||
writeErr: (str) => process.stdout.write(`[ERR] ${str}`), | ||
// Output errors in red. | ||
outputError: (str, write) => write(red(str)) | ||
}); | ||
|
||
program | ||
.version('1.2.3') | ||
.option('-c, --compress') | ||
.command('sub-command'); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node configure-output.js --version | ||
// node configure-output.js --unknown | ||
// node configure-output.js --help | ||
// node configure-output.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found it difficult to understand the
red
function because it came out of nowhere.How about including the following in the readme code examples as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good feedback, will do. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched name to
errorColor
(which was what I called this in one of my own programs!) and added implementation to README as suggested.