Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/steelbrain/command
CLI command and options parser
https://github.com/steelbrain/command
Last synced: 10 days ago
JSON representation
CLI command and options parser
- Host: GitHub
- URL: https://github.com/steelbrain/command
- Owner: steelbrain
- License: mit
- Created: 2016-12-12T14:34:38.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-13T16:28:05.000Z (almost 6 years ago)
- Last Synced: 2024-08-10T22:56:50.647Z (3 months ago)
- Language: JavaScript
- Size: 112 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
sb-command
=========[![Greenkeeper badge](https://badges.greenkeeper.io/steelbrain/command.svg)](https://greenkeeper.io/)
sb-command is the CLI parser you'll ever need.
## Documentation
There are several types of parameters
- `[name]` means `name` is an optional parameter
- `` means `name` is a required parameter
- `[name...]` means `name` is an optional variadic parameter
- `` means `name` is a required variadic parameter
- Specifying no parameter with an option means it's booleanTo add nested commands, simply join them with dot. For example for `remote add` use `remote.add` as the command name.
To add configs specific to certain commands, do the `.option()` call after *that* particular `.command()` call. If you want your configs to be global, add them before adding any other command.
### Example
```js
const command = require('sb-command')command
.version('0.0.1')
.description('Git Versonal Control System')
.option('--disable-cache', 'Disable Git Cache')
.command('init', 'Initialize an empty repo', function(options) {
console.log('git-init')
})
.option('--shallow-copy', 'Initialize with shallow copy')
.command('add [file]', 'Add file contents to index', function(options, file) {
console.log('git-add', files)
})
.option('--dry-run', 'Try to stage the file into git index but dont actually do it')
.default(function(options, parameters) {
console.log(options, parameters)
})
.process()```
### API
```js
export class Command {
default(callback: Function): this
version(version: string): this
description(descriptionText: string): this
command(commandName: string, description: string, callback: ?Function): this
option(option: string, description: string, defaultValue: any = null): this
process(argv: Array = process.argv): Promise
showHelp(): string
}
export default new command
```## LICENSE
This package is licensed under the terms of MIT License. See the LICENSE file for more info.