Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mcollina/commist
Build your commands on minimist!
https://github.com/mcollina/commist
Last synced: 5 days ago
JSON representation
Build your commands on minimist!
- Host: GitHub
- URL: https://github.com/mcollina/commist
- Owner: mcollina
- License: mit
- Created: 2014-08-12T13:36:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-02-12T09:09:13.000Z (10 months ago)
- Last Synced: 2024-10-30T00:32:29.076Z (about 2 months ago)
- Language: JavaScript
- Size: 36.1 KB
- Stars: 99
- Watchers: 5
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
commist
=======Build command line application with multiple commands the easy way.
To be used with [minimist](http://npm.im/minimist).```js
'use strict'const program = require('commist')()
const result = program
.register('abcd', function(args) {
console.log('just do', args)
})
.register({ command: 'restore', equals: true }, function(args) {
console.log('restore', args)
})
.register('args', function(args) {
args = minimist(args)
console.log('just do', args)
})
.register('abcde code', function(args) {
console.log('doing something', args)
})
.register('another command', function(args) {
console.log('anothering', args)
})
.parse(process.argv.splice(2))if (result) {
console.log('no command called, args', result)
}
```To handle `async` operations, use `parseAsync` instead,
which let you await on registered commands execution.```js
'use strict'const program = require('commist')()
const result = await program
.register('abcd', async function(args) {
await executeCommand(args)
await doOtherStuff()
})
.parseAsync(process.argv.splice(2))if (result) {
console.log('no command called, args', result)
}
```When calling _commist_ programs, you can abbreviate down to three char
words. In the above example, these are valid commands:```
node example.js abc
node example.js abc cod
node example.js anot comm
```Moreover, little spelling mistakes are corrected too:
```
node example.js abcs cod
```If you want that the command must be strict equals, you can register the
command with the json configuration:```js
program.register({ command: 'restore', strict: true }, function(args) {
console.log('restore', args)
})
```If you want to limit the maximum levenshtein distance of your commands,
you can use `maxDistance: 2`:```js
const program = require('commist')()
const minimist = require('minimist')const result = program
.register('abcd', function(args) {
console.log('just do', args)
})
.register({ command: 'restore', equals: true }, function(args) {
console.log('restore', args)
})
.register('args', function(args) {
args = minimist(args)
console.log('just do', args)
})
.register('abcde code', function(args) {
console.log('doing something', args)
})
.register('another command', function(args) {
console.log('anothering', args)
})
.parse(process.argv.splice(2))if (result) {
console.log('no command called, args', result)
}
```License
-------MIT