-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 694c619
Showing
11 changed files
with
255 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[package.json] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"node": true, | ||
"esnext": true, | ||
"bitwise": true, | ||
"camelcase": true, | ||
"curly": true, | ||
"immed": true, | ||
"newcap": true, | ||
"noarg": true, | ||
"undef": true, | ||
"unused": "vars", | ||
"strict": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
var path = require('path'); | ||
var minimist = require('minimist'); | ||
var indentString = require('indent-string'); | ||
var objectAssign = require('object-assign'); | ||
var camelcaseKeys = require('camelcase-keys'); | ||
|
||
// needed to get the uncached parent | ||
delete require.cache[__filename]; | ||
var parentDir = path.dirname(module.parent.filename); | ||
|
||
module.exports = function (opts, minimistOpts) { | ||
opts = objectAssign({ | ||
pkg: './package.json', | ||
requireInput: true, | ||
argv: process.argv.slice(2) | ||
}, opts); | ||
|
||
var pkg = require(path.join(parentDir, opts.pkg)); | ||
var argv = minimist(opts.argv, minimistOpts); | ||
var errHelp = (opts.requireInput && !argv.help && argv._.length === 0); | ||
var helpText = '\n' + indentString(pkg.description + (opts.help ? '\n\n' + opts.help : '\n'), ' '); | ||
|
||
if (argv.version) { | ||
console.log(pkg.version); | ||
process.exit(); | ||
} | ||
|
||
if (errHelp) { | ||
console.error(helpText); | ||
process.exit(1); | ||
} | ||
|
||
if (argv.help) { | ||
console.log(helpText); | ||
process.exit(); | ||
} | ||
|
||
var _ = argv._; | ||
delete argv._; | ||
|
||
return { | ||
input: _, | ||
flags: camelcaseKeys(argv), | ||
pkg: pkg | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "meow", | ||
"version": "0.0.0", | ||
"description": "CLI app helper", | ||
"license": "MIT", | ||
"repository": "sindresorhus/meow", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "http://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
}, | ||
"scripts": { | ||
"test": "node test.js" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"cli", | ||
"bin", | ||
"util", | ||
"utility", | ||
"helper", | ||
"argv" | ||
], | ||
"dependencies": { | ||
"camelcase-keys": "^1.0.0", | ||
"indent-string": "^1.1.0", | ||
"minimist": "^1.1.0", | ||
"object-assign": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "0.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# meow [](https://travis-ci.org/sindresorhus/meow) | ||
|
||
> CLI app helper | ||
 | ||
|
||
|
||
## Features | ||
|
||
- Parses arguments using [minimist](https://github.com/substack/minimist) | ||
- Converts flags to [camelCase](https://github.com/sindresorhus/camelcase) | ||
- Outputs version when `--version` | ||
- Outputs description and supplied help text when `--help` | ||
- Outputs the above when no input is supplied *[(can be disabled)](#requireinput)* | ||
|
||
|
||
## Install | ||
|
||
```sh | ||
$ npm install --save meow | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```sh | ||
$ ./foo-app.js unicorns --rainbow-cake | ||
``` | ||
|
||
```js | ||
#!/usr/bin/env node | ||
'use strict'; | ||
var meow = require('meow'); | ||
var fooApp = require('./'); | ||
|
||
var cli = meow({ | ||
help: [ | ||
'Usage', | ||
' foo-app <input>' | ||
].join('\n') | ||
}); | ||
/* | ||
{ | ||
input: ['unicorns'], | ||
flags: {rainbowCake: true}, | ||
pkg: { | ||
name: 'foo-app', | ||
... | ||
} | ||
*/ | ||
|
||
fooApp(cli.input[0], cli.flags); | ||
``` | ||
|
||
|
||
## API | ||
|
||
### meow(options, minimistOptions) | ||
|
||
Returns an object with: | ||
|
||
- `input` *(array)* - Non-flag arguments | ||
- `flags` *(object)* - Flags converted to camelCase | ||
- `pkg` *(object)* - The `package.json` object | ||
|
||
#### options | ||
|
||
##### help | ||
|
||
Type: `string` | ||
|
||
The help text you want shown. | ||
|
||
##### pkg | ||
|
||
Type: `string` | ||
Default: `package.json` | ||
|
||
Relative path to `package.json`. | ||
|
||
##### requireInput | ||
|
||
Type: `boolean` | ||
Default: `true` | ||
|
||
Require there to be at least one input argument. | ||
|
||
##### argv | ||
|
||
Type: `array` | ||
Default: `process.argv.slice(2)` | ||
|
||
Custom arguments object. | ||
|
||
#### minimistOptions | ||
|
||
Type: `object` | ||
Default: `{}` | ||
|
||
Minimist [options](https://github.com/substack/minimist#var-argv--parseargsargs-opts). | ||
|
||
|
||
## License | ||
|
||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use strict'; | ||
var test = require('ava'); | ||
var meow = require('./'); | ||
|
||
test('return object', function (t) { | ||
var cli = meow({argv: ['foo', '--foo-bar']}); | ||
t.assert(cli.input[0] === 'foo'); | ||
t.assert(cli.flags.fooBar); | ||
t.assert(cli.pkg.name === 'meow'); | ||
t.end(); | ||
}); |