Socket
Socket
Sign inDemoInstall

meow

Package Overview
Dependencies
53
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.7.0 to 4.0.0

94

index.js
'use strict';
var path = require('path');
var minimist = require('minimist');
var objectAssign = require('object-assign');
var camelcaseKeys = require('camelcase-keys');
var decamelize = require('decamelize');
var mapObj = require('map-obj');
var trimNewlines = require('trim-newlines');
var redent = require('redent');
var readPkgUp = require('read-pkg-up');
var loudRejection = require('loud-rejection');
var normalizePackageData = require('normalize-package-data');
const path = require('path');
const buildMinimistOptions = require('minimist-options');
const minimist = require('minimist');
const camelcaseKeys = require('camelcase-keys');
const decamelizeKeys = require('decamelize-keys');
const trimNewlines = require('trim-newlines');
const redent = require('redent');
const readPkgUp = require('read-pkg-up');
const loudRejection = require('loud-rejection');
const normalizePackageData = require('normalize-package-data');
// get the uncached parent
// Prevent caching of this module so module.parent is always accurate
delete require.cache[__filename];
var parentDir = path.dirname(module.parent.filename);
const parentDir = path.dirname(module.parent.filename);
module.exports = function (opts, minimistOpts) {
module.exports = (helpMessage, opts) => {
loudRejection();
if (Array.isArray(opts) || typeof opts === 'string') {
opts = {help: opts};
if (typeof helpMessage === 'object' && !Array.isArray(helpMessage)) {
opts = helpMessage;
helpMessage = '';
}
opts = objectAssign({
opts = Object.assign({
pkg: readPkgUp.sync({

@@ -30,19 +30,26 @@ cwd: parentDir,

}).pkg,
argv: process.argv.slice(2)
argv: process.argv.slice(2),
inferType: false,
input: 'string',
help: helpMessage,
autoHelp: true,
autoVersion: true
}, opts);
minimistOpts = objectAssign({}, minimistOpts);
let minimistOpts = Object.assign({
arguments: opts.input
}, opts.flags);
minimistOpts.default = mapObj(minimistOpts.default || {}, function (key, value) {
return [decamelize(key, '-'), value];
});
minimistOpts = decamelizeKeys(minimistOpts, '-', {exclude: ['stopEarly', '--']});
if (Array.isArray(opts.help)) {
opts.help = opts.help.join('\n');
if (opts.inferType) {
delete minimistOpts.arguments;
}
var pkg = typeof opts.pkg === 'string' ? require(path.join(parentDir, opts.pkg)) : opts.pkg;
var argv = minimist(opts.argv, minimistOpts);
var help = redent(trimNewlines(opts.help || ''), 2);
minimistOpts = buildMinimistOptions(minimistOpts);
const pkg = opts.pkg;
const argv = minimist(opts.argv, minimistOpts);
let help = redent(trimNewlines((opts.help || '').replace(/\t+\n*$/, '')), 2);
normalizePackageData(pkg);

@@ -52,3 +59,3 @@

var description = opts.description;
let description = opts.description;
if (!description && description !== false) {

@@ -58,28 +65,35 @@ description = pkg.description;

help = (description ? '\n ' + description + '\n' : '') + (help ? '\n' + help : '\n');
help = (description ? `\n ${description}\n` : '') + (help ? `\n${help}\n` : '\n');
var showHelp = function (code) {
const showHelp = code => {
console.log(help);
process.exit(code || 0);
process.exit(typeof code === 'number' ? code : 2);
};
if (argv.version && opts.version !== false) {
const showVersion = () => {
console.log(typeof opts.version === 'string' ? opts.version : pkg.version);
process.exit();
};
if (argv.version && opts.autoVersion) {
showVersion();
}
if (argv.help && opts.help !== false) {
showHelp();
if (argv.help && opts.autoHelp) {
showHelp(0);
}
var _ = argv._;
const input = argv._;
delete argv._;
const flags = camelcaseKeys(argv, {exclude: ['--', /^\w$/]});
return {
input: _,
flags: camelcaseKeys(argv),
pkg: pkg,
help: help,
showHelp: showHelp
input,
flags,
pkg,
help,
showHelp,
showVersion
};
};
{
"name": "meow",
"version": "3.7.0",
"description": "CLI app helper",
"license": "MIT",
"repository": "sindresorhus/meow",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"cli",
"bin",
"util",
"utility",
"helper",
"argv",
"command",
"line",
"meow",
"cat",
"kitten",
"parser",
"option",
"flags",
"input",
"cmd",
"console"
],
"dependencies": {
"camelcase-keys": "^2.0.0",
"decamelize": "^1.1.2",
"loud-rejection": "^1.0.0",
"map-obj": "^1.0.1",
"minimist": "^1.1.3",
"normalize-package-data": "^2.3.4",
"object-assign": "^4.0.1",
"read-pkg-up": "^1.0.1",
"redent": "^1.0.0",
"trim-newlines": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.1.1",
"indent-string": "^2.1.0",
"xo": "*"
}
"name": "meow",
"version": "4.0.0",
"description": "CLI app helper",
"license": "MIT",
"repository": "sindresorhus/meow",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js"
],
"keywords": [
"cli",
"bin",
"util",
"utility",
"helper",
"argv",
"command",
"line",
"meow",
"cat",
"kitten",
"parser",
"option",
"flags",
"input",
"cmd",
"console"
],
"dependencies": {
"camelcase-keys": "^4.0.0",
"decamelize-keys": "^1.0.0",
"loud-rejection": "^1.0.0",
"minimist": "^1.1.3",
"minimist-options": "^3.0.1",
"normalize-package-data": "^2.3.4",
"read-pkg-up": "^3.0.0",
"redent": "^2.0.0",
"trim-newlines": "^2.0.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.8.0",
"indent-string": "^3.0.0",
"xo": "*"
},
"xo": {
"rules": {
"unicorn/no-process-exit": "off"
}
}
}

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

- Parses arguments using [minimist](https://github.com/substack/minimist)
- Parses arguments
- Converts flags to [camelCase](https://github.com/sindresorhus/camelcase)

@@ -22,3 +22,3 @@ - Outputs version when `--version`

```
$ npm install --save meow
$ npm install meow
```

@@ -30,3 +30,3 @@

```
$ ./foo-app.js unicorns --rainbow-cake
$ ./foo-app.js unicorns --rainbow
```

@@ -38,3 +38,3 @@

const meow = require('meow');
const foo = require('./');
const foo = require('.');

@@ -46,3 +46,3 @@ const cli = meow(`

Options
-r, --rainbow Include a rainbow
--rainbow, -r Include a rainbow

@@ -53,4 +53,7 @@ Examples

`, {
alias: {
r: 'rainbow'
flags: {
rainbow: {
type: 'boolean',
alias: 'r'
}
}

@@ -74,22 +77,48 @@ });

Returns an object with:
Returns an `Object` with:
- `input` *(array)* - Non-flag arguments
- `flags` *(object)* - Flags converted to camelCase
- `pkg` *(object)* - The `package.json` object
- `help` *(object)* - The help text used with `--help`
- `showHelp([code=0])` *(function)* - Show the help text and exit with `code`
- `input` *(Array)* - Non-flag arguments
- `flags` *(Object)* - Flags converted to camelCase
- `pkg` *(Object)* - The `package.json` object
- `help` *(string)* - The help text used with `--help`
- `showHelp([code=2])` *(Function)* - Show the help text and exit with `code`
- `showVersion()` *(Function)* - Show the version text and exit
#### options
Type: `object`, `array`, `string`
Type: `Object` `Array` `string`
Can either be a string/array that is the `help` or an options object.
##### flags
Type: `Object`
Define argument flags.
The key is the flag name and the value is an object with any of:
- `type`: Type of value. (Possible values: `string` `boolean`)
- `alias`: Usually used to define a short flag alias.
- `default`: Default value when the flag is not specified.
Example:
```js
flags: {
unicorn: {
type: 'string',
alias: 'u',
default: 'rainbow'
}
}
```
##### description
Type: `string`, `boolean`
Type: `string` `boolean`<br>
Default: The package.json `"description"` property
A description to show above the help text.
Description to show above the help text.

@@ -100,3 +129,3 @@ Set it to `false` to disable it altogether.

Type: `string`, `boolean`
Type: `string` `boolean`

@@ -107,12 +136,7 @@ The help text you want shown.

<del>If it's an array each item will be a line.</del>
*(Still supported, but you should use a template literal instead.)*
The description will be shown above your help text automatically.
Set it to `false` to disable it altogether.
##### version
Type: `string`, `boolean`
Type: `string` `boolean`<br>
Default: The package.json `"version"` property

@@ -122,14 +146,28 @@

Set it to `false` to disable it altogether.
##### autoHelp
Type: `boolean`<br>
Default: `true`
Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text.
##### autoVersion
Type: `boolean`<br>
Default: `true`
Automatically show the version text when the `--version` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own version text.
##### pkg
Type: `string`, `object`
Type: `Object`<br>
Default: Closest package.json upwards
Relative path to package.json or as an object.
package.json as an `Object`.
*You most likely don't need this option.*
##### argv
Type: `array`
Type: `Array`<br>
Default: `process.argv.slice(2)`

@@ -139,10 +177,10 @@

#### minimistOptions
##### inferType
Type: `object`
Default: `{}`
Type: `boolean`<br>
Default: `false`
Minimist [options](https://github.com/substack/minimist#var-argv--parseargsargs-opts).
Infer the argument type.
Keys passed to the minimist `default` option are [decamelized](https://github.com/sindresorhus/decamelize), so you can for example pass in `fooBar: 'baz'` and have it be the default for the `--foo-bar` flag.
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.

@@ -161,11 +199,11 @@

See [`conf`](https://github.com/sindresorhus/conf) if you need to persist some data.
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)
[More useful CLI utilities.](https://github.com/sindresorhus/awesome-nodejs#command-line-utilities)
## License
MIT © [Sindre Sorhus](http://sindresorhus.com)
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

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