Comparing version 14.1.1 to 15.0.0
@@ -1,6 +0,42 @@ | ||
const Command = require('./lib/command') | ||
const parse = require('./lib/parse') | ||
const parse = require('./parse') | ||
const error = require('./error') | ||
const help = require('./help') | ||
module.exports = function (args) { | ||
return new Command(args || parse(process.argv.slice(2))) | ||
module.exports = function (name, define) { | ||
const definitions = {} | ||
option('help', { | ||
type: Boolean, | ||
aliases: ['h'], | ||
description: 'get help' | ||
}) | ||
let i = 0 | ||
const action = define({option, parameter}) | ||
return (argv) => { | ||
try { | ||
const args = parse(argv, definitions) | ||
if (args.help === true) { | ||
help(name, definitions) | ||
} else { | ||
const result = action(args) | ||
if (typeof result === 'object' && result instanceof Promise) { | ||
result.catch(error) | ||
} | ||
} | ||
} catch (e) { | ||
error(e) | ||
} | ||
} | ||
function option (key, definition) { | ||
definitions[key] = definition | ||
} | ||
function parameter (key, definition) { | ||
definitions[i++] = Object.assign(definition, {key}) | ||
} | ||
} |
{ | ||
"name": "sergeant", | ||
"version": "14.1.1", | ||
"version": "15.0.0", | ||
"description": "", | ||
"main": "application.js", | ||
"main": "command.js", | ||
"scripts": { | ||
"test": "standard && tape 'test/**/*.js' | faucet", | ||
"test": "standard && tape test.js | faucet", | ||
"cover": "nyc --reporter=html npm test" | ||
@@ -9,0 +9,0 @@ }, |
# sergeant | ||
A CLI solution inspired by [Commander.js](https://github.com/tj/commander.js). | ||
## an example (multiple commands) | ||
```javascript | ||
var app = require('sergeant')() | ||
var assert = require('assert') | ||
app.command('command1') | ||
.parameter('param1', 'param1') | ||
.option('option1', 'option1') | ||
.action(function (args) { | ||
assert.ok(args.get('param1'), 'param1 is required') | ||
return Promise.resolve(true) | ||
}) | ||
app.command('command2') | ||
.parameter('param2', 'param2') | ||
.option('option2', 'option2') | ||
.action(function (args) { | ||
assert.ok(args.get('param2'), 'param2 is required') | ||
return Promise.resolve(true) | ||
}) | ||
app.run() | ||
``` | ||
## an example (single command) | ||
```javascript | ||
var command = require('sergeant/command')() | ||
var assert = require('assert') | ||
command | ||
.parameter('param1', 'param1') | ||
.option('option1', 'option1') | ||
.action(function (args) { | ||
assert.ok(args.get('param1'), 'param1 is required') | ||
return Promise.resolve(true) | ||
}) | ||
command.run() | ||
``` | ||
A CLI solution with simple argument parsing and built in help messages |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19067
10
627
4
1