Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add output configuration and use for version and errors * Tests passing using write/writeErr * Suppress test output on stderr using spyon * Accurately set help columns for stdout/stderr * Remove bogus file * Tidy comments * Only using single argument to write, simplify declaration to match * Add tests for configureOutput write and writeError * Add tests for configureOutput getColumns and getErrorColumns * Add error case too * Use configureOutput instead of jest.spyon for some tests * Add configureOutput to chain tests * Add set/get test for configureOutput * Rename routines with symmetrical out/err * Add outputError simple code * Add tests for outputError * Add JSDoc * Tweak wording * First cut at TypeScript * Add TypeScript sanity check for configureOutput * Add example for configureOutput * Add configureOutput to README * Make example in README a little clearer
- Loading branch information
1 parent
2f7aa33
commit ed7f13e
Showing
19 changed files
with
499 additions
and
125 deletions.
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,31 @@ | ||
// const commander = require('commander'); // (normal include) | ||
const commander = require('../'); // include commander in git clone of commander repo | ||
|
||
const program = new commander.Command(); | ||
|
||
function errorColor(str) { | ||
// Add ANSI escape codes to display text in red. | ||
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(errorColor(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.