Socket
Socket
Sign inDemoInstall

meow

Package Overview
Dependencies
49
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 3.4.0

26

index.js
'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');
var trimNewlines = require('trim-newlines');
var redent = require('redent');
var readPkgUp = require('read-pkg-up');
var loudRejection = require('loud-rejection');
// needed to get the uncached parent
// get the uncached parent
delete require.cache[__filename];

@@ -13,4 +16,10 @@ var parentDir = path.dirname(module.parent.filename);

module.exports = function (opts, minimistOpts) {
loudRejection();
if (Array.isArray(opts) || typeof opts === 'string') {
opts = {help: opts};
}
opts = objectAssign({
pkg: './package.json',
pkg: readPkgUp.sync({cwd: parentDir}).pkg,
argv: process.argv.slice(2)

@@ -25,6 +34,11 @@ }, opts);

var argv = minimist(opts.argv, minimistOpts);
var help = '\n' + indentString(pkg.description + (opts.help ? '\n\n' + opts.help : '\n'), ' ');
var showHelp = function () {
var help = redent(trimNewlines(opts.help), 2);
process.title = pkg.bin ? Object.keys(pkg.bin)[0] : pkg.name;
help = '\n ' + pkg.description + (help ? '\n\n' + help : '\n');
var showHelp = function (code) {
console.log(help);
process.exit();
process.exit(code || 0);
};

@@ -31,0 +45,0 @@

{
"name": "meow",
"version": "3.3.0",
"version": "3.4.0",
"description": "CLI app helper",

@@ -16,3 +16,3 @@ "license": "MIT",

"scripts": {
"test": "node test.js"
"test": "xo && ava"
},

@@ -43,9 +43,14 @@ "files": [

"camelcase-keys": "^1.0.0",
"indent-string": "^1.1.0",
"minimist": "^1.1.0",
"object-assign": "^3.0.0"
"loud-rejection": "^1.0.0",
"minimist": "^1.1.3",
"object-assign": "^4.0.1",
"read-pkg-up": "^1.0.1",
"redent": "^1.0.0",
"trim-newlines": "^1.0.0"
},
"devDependencies": {
"ava": "0.0.4"
"ava": "*",
"indent-string": "^2.1.0",
"xo": "*"
}
}

@@ -14,2 +14,4 @@ # meow [![Build Status](https://travis-ci.org/sindresorhus/meow.svg?branch=master)](https://travis-ci.org/sindresorhus/meow)

- Outputs description and supplied help text when `--help`
- Makes unhandled rejected promises [fail loudly](https://github.com/sindresorhus/loud-rejection) instead of the default silent fail
- Sets the process title to the binary name defined in package.json

@@ -33,10 +35,19 @@

'use strict';
var meow = require('meow');
var fooApp = require('./');
const meow = require('meow');
const foo = require('./');
var cli = meow({
help: [
'Usage',
' foo-app <input>'
]
const cli = meow(`
Usage
$ foo <input>
Options
-r, --rainbow Include a rainbow
Examples
$ foo unicorns --rainbow
🌈 unicorns 🌈
`, {
alias: {
r: 'rainbow'
}
});

@@ -46,3 +57,3 @@ /*

input: ['unicorns'],
flags: {rainbowCake: true},
flags: {rainbow: true},
...

@@ -52,3 +63,3 @@ }

fooApp(cli.input[0], cli.flags);
foo(cli.input[0], cli.flags);
```

@@ -59,3 +70,3 @@

### meow(options, minimistOptions)
### meow(options, [minimistOptions])

@@ -68,14 +79,21 @@ Returns an object with:

- `help` *(object)* - The help text used with `--help`
- `showHelp()` *(function)* - Show the help text and exit
- `showHelp([code=0])` *(function)* - Show the help text and exit with `code`
#### options
Type: `object`, `array`, `string`
Can either be a string/array that is the `help` or an options object.
##### help
Type: `array`, `string`, `boolean`
Type: `string`, `boolean`
The help text you want shown.
If it's an array each item will be a line.
The input is reindented and starting/ending newlines are trimmed which means you can use a [template literal](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) without having to care about using the correct amount of indent.
<del>If it's an array each item will be a line.</del>
*(Still supported, but you should use a template literal instead.)*
If you don't specify anything, it will still show the package.json `"description"`.

@@ -88,3 +106,3 @@

Type: `string`, `boolean`
Default: the package.json `"version"` property
Default: The package.json `"version"` property

@@ -98,5 +116,5 @@ Set a custom version output.

Type: `string`, `object`
Default: `package.json`
Default: Closest package.json upwards
Relative path to `package.json` or it as an object.
Relative path to package.json or as an object.

@@ -118,9 +136,22 @@ ##### argv

## Tip
## Promises
Use [get-stdin](https://github.com/sindresorhus/get-stdin) if you need to accept input from stdin.
Meow will make unhandled rejected promises [fail loudly](https://github.com/sindresorhus/loud-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI.
## Tips
See [`chalk`](https://github.com/chalk/chalk) if you want to colorize the terminal output.
See [`get-stdin`](https://github.com/sindresorhus/get-stdin) if you want to accept input from stdin.
See [`update-notifier`](https://github.com/yeoman/update-notifier) if you want update notifications.
See [`configstore`](https://github.com/yeoman/configstore) if you need to persist some data.
[More useful CLI utilities.](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc