Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor README examples into a QuickStart (#1665)
* Quick Start * Update comments * Update quick start examples so README and code match
- Loading branch information
1 parent
c6e0ee8
commit 4b9fee9
Showing
3 changed files
with
136 additions
and
67 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,19 @@ | ||
// const { program } = require('commander'); // (normal include) | ||
const { program } = require('../'); // include commander in git clone of commander repo | ||
|
||
// This is used as an example in the README for the Quick Start. | ||
|
||
program | ||
.option('--first') | ||
.option('-s, --separator <char>'); | ||
|
||
program.parse(); | ||
|
||
const options = program.opts(); | ||
const limit = options.first ? 1 : undefined; | ||
console.log(program.args[0].split(options.separator, limit)); | ||
|
||
// Try the following: | ||
// node split -s / --fits a/b/c | ||
// node split -s / --first a/b/c | ||
// node split --separator=, a,b,c |
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,37 @@ | ||
// const { Command } = require('commander'); // (normal include) | ||
const { Command } = require('../'); // include commander in git clone of commander repo | ||
const program = new Command(); | ||
|
||
// This is used as an example in the README for the Quick Start. | ||
|
||
program | ||
.name('string-util') | ||
.description('CLI to some JavaScript string utilities') | ||
.version('0.8.0'); | ||
|
||
program.command('split') | ||
.description('Split a string into substrings and display as an array.') | ||
.argument('<string>', 'string to split') | ||
.option('--first', 'display just the first substring') | ||
.option('-s, --separator <char>', 'separator character', ',') | ||
.action((str, options) => { | ||
const limit = options.first ? 1 : undefined; | ||
console.log(str.split(options.separator, limit)); | ||
}); | ||
|
||
program.command('join') | ||
.description('Join the command-arguments into a single string') | ||
.argument('<strings...>', 'one or more strings') | ||
.option('-s, --separator <char>', 'separator character', ',') | ||
.action((strings, options) => { | ||
console.log(strings.join(options.separator)); | ||
}); | ||
|
||
program.parse(); | ||
|
||
// Try the following: | ||
// node string-util | ||
// node string-util help split | ||
// node string-util split --separator=/ a/b/c | ||
// node string-util split --first a,b,c | ||
// node string-util join a b c d |
4b9fee9
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.
The idea is if you make a clone of this repository, and change directory into the examples folder, you can follow the instructions in "Try the following".
e.g.