command-line-basics
Wraps the following basic command-line functionality to your package:
- Utilizes
update-notifier
to notify the user of any updates of your
package. - By default, will automatically add
--version
/-v
and --help
/-h
flags to the options defined in your targeted file's definitions
(processed by command-line-args
) and sections[1].optionList
(processed
by command-line-usage
). When your users call --help
, these two flags
will be shown there. When your users call --version
, it will output
the current version
of your package.json
). - By default, will automatically add
header
to sections[0]
if not
present (based on the name
in package.json
).
Install
npm i -P command-line-basics
Simple usage
const {cliBasics} = require('command-line-basics');
const optionDefinitions = cliBasics(
path.join(__dirname, '../src/optionDefinitions.js')
);
if (!optionDefinitions) {
process.exit();
}
Advanced usage
Except for optionsPath
, the example indicates the defaults:
const {cliBasics} = require('command-line-basics');
const options = cliBasics({
optionsPath: path.join(process.cwd(), './src/optionDefinitions.js'),
cwd: __dirname,
options: {
packageJsonPath: path.join(process.cwd(), 'package.json'),
autoAddVersion: true,
autoAddHelp: true,
autoAddHeader: true,
updateNotifierOptions: {
updateCheckInterval: 1000 * 60 * 60 * 24,
callback () {
},
shouldNotifyInNpmScript: false,
distTag: 'latest'
},
updateNotifierNotifyOptions: {
defer: false,
message: '',
isGlobal: defaultsToAutoDetectBoolean,
boxenOpts: {
padding: 1, margin: 1, align: 'center',
borderColor: 'yellow', borderStyle: 'round'
}
}
}
});
if (!options) {
process.exit();
}
There is also exported an autoAdd
method which takes the same arguments
and returns the (potentially help
/version
and header
enhanced)
definitions
and sections
. It is also used internally by cliBasics
.
To-dos
- Could auto-add
content
based on pkg.description
and Options
as
sections[1].header
.