Skip to content

Commit

Permalink
Readme note about normalizing quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Oct 12, 2023
1 parent 6de0aaa commit 93bc4c8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,26 @@ Place the following code in your **bin/cli.js** file
import { cliArgvUtil } from 'cli-argv-util';

const validFlags = ['cd', 'find', 'no-summary'];
const cli = cliArgvUtil.parse(validFlags);
if (cliArgvUtil.invalidFlag)
throw Error(cliArgvUtil.invalidFlagMsg);
const cli = cliArgvUtil.parse(validFlags);
if (cli.invalidFlag)
throw Error(cli.invalidFlagMsg);
if (cli.flagOn.find)
console.log('You set the --find CLI flag to:', cli.flagMap.find);
if (cli.flagOn.noSummary)
console.log('You enabled the --no-summary CLI option.');
console.log('You supplied', cli.params.length , 'CLI parameter(s).');
```
For a real world example, see: [cli.js](https://github.com/center-key/copy-file-util/blob/main/bin/cli.js)

If your CLI tool is named `my-program` and a user runs it like:
```shell
$ my-program file.html --cd=src --no-summary file.png
$ my-program about.html --cd=src --no-summary 'Hello World' 777
```
the resulting `cli` object will be:
```javascript
{
flagMap: {
cd: 'src',
noSummary: undefined,
cd: 'src',
},
flagOn: {
cd: true,
Expand All @@ -47,9 +51,10 @@ the resulting `cli` object will be:
},
invalidFlag: null,
invalidFlagMsg: null,
params: ['file.html', 'file.png'],
params: ['about.html', 'Hello World', '777'],
}
```
_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._

## C) Results
The `cliArgvUtil.parse()` returns an object of type `Result`:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@
"slash": "~5.1"
},
"devDependencies": {
"@types/node": "~20.6",
"@types/node": "~20.8",
"@typescript-eslint/eslint-plugin": "~6.7",
"@typescript-eslint/parser": "~6.7",
"add-dist-header": "~1.3",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"eslint": "~8.50",
"eslint": "~8.51",
"jshint": "~2.13",
"mocha": "~10.2",
"rimraf": "~5.0",
Expand Down
2 changes: 1 addition & 1 deletion task-runner.sh.command
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ releaseInstructions() {
echo "When ready to do the next release:"
echo
echo " === Increment version ==="
echo " Edit pacakge.json to bump $version to next version number"
echo " Edit package.json to bump $version to next version number"
echo " $projectHome/package.json"
}
nextActionCommitTagPub() {
Expand Down

0 comments on commit 93bc4c8

Please sign in to comment.