https://github.com/cmr1/node-cli
NodeJS CLI module
https://github.com/cmr1/node-cli
cli node node-cli node-js node-module nodejs nodejs-cli
Last synced: 3 months ago
JSON representation
NodeJS CLI module
- Host: GitHub
- URL: https://github.com/cmr1/node-cli
- Owner: cmr1
- License: mit
- Created: 2017-01-30T18:51:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-08-10T20:07:39.000Z (almost 4 years ago)
- Last Synced: 2025-02-10T10:23:44.286Z (4 months ago)
- Topics: cli, node, node-cli, node-js, node-module, nodejs, nodejs-cli
- Language: JavaScript
- Size: 881 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://codeclimate.com/github/cmr1/node-cli/maintainability)
[](https://codeclimate.com/github/cmr1/node-cli/test_coverage)[](https://www.npmjs.com/package/cmr1-cli)
[](https://travis-ci.org/cmr1/node-cli)# cli-node
NodeJS CLI module## Example: (from `scratch.js`)
```javascript
const Cmr1Cli = require('cmr1-cli');const additionalOptions = [
{
name: 'src',
alias: 's',
type: String,
multiple: true,
defaultOption: true,
description: 'Input source',
typeLabel: '[underline]{file}'
},
{
name: 'timeout',
alias: 't',
type: Number,
description: 'Timeout',
typeLabel: '[underline]{ms}'
}
];const myCli = new Cmr1Cli({
name: 'My CLI script name',
description: 'A description of this script',
helpHeader: 'Available Options',
optionDefinitions: additionalOptions,
logging: {
test: {
verbose: true, // Consider this debug, only show when verbose
throws: false, // Should this log type throw an Error?
stamp: true, // Also prefix log output with a timestamp
prefix: 'Test', // Prefix string to show before each log msg
color: 'blue' // Color of output text (FG only)
}
}
});Object.keys(myCli.settings.logging).forEach(type => {
myCli[type](`This is a(n) ${type} message!`);
myCli[type](`Called using: myCli.${type}('message')`)
});additionalOptions.forEach(option => {
const name = option.name;
const value = myCli.options[name];myCli.log(`Option '${name}' = '${value}'`);
});```
### Example console output:
**Command:** `node scratch.js --src /path/to/input/file --timeout 1000 -fv`
### Example help menu:
**Command:** `node scratch.js --help`