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 4.0.1 to 5.0.0

58

index.js
'use strict';
const path = require('path');
const buildMinimistOptions = require('minimist-options');
const minimist = require('minimist');
const yargs = require('yargs-parser');
const camelcaseKeys = require('camelcase-keys');

@@ -17,11 +17,11 @@ const decamelizeKeys = require('decamelize-keys');

module.exports = (helpMessage, opts) => {
module.exports = (helpMessage, options) => {
loudRejection();
if (typeof helpMessage === 'object' && !Array.isArray(helpMessage)) {
opts = helpMessage;
options = helpMessage;
helpMessage = '';
}
opts = Object.assign({
options = Object.assign({
pkg: readPkgUp.sync({

@@ -36,21 +36,37 @@ cwd: parentDir,

autoHelp: true,
autoVersion: true
}, opts);
autoVersion: true,
booleanDefault: false
}, options);
let minimistOpts = Object.assign({
arguments: opts.input
}, opts.flags);
const minimistFlags = options.flags && typeof options.booleanDefault !== 'undefined' ? Object.keys(options.flags).reduce(
(flags, flag) => {
if (flags[flag].type === 'boolean' && !Object.prototype.hasOwnProperty.call(flags[flag], 'default')) {
flags[flag].default = options.booleanDefault;
}
minimistOpts = decamelizeKeys(minimistOpts, '-', {exclude: ['stopEarly', '--']});
return flags;
},
options.flags
) : options.flags;
if (opts.inferType) {
delete minimistOpts.arguments;
let minimistoptions = Object.assign({
arguments: options.input
}, minimistFlags);
minimistoptions = decamelizeKeys(minimistoptions, '-', {exclude: ['stopEarly', '--']});
if (options.inferType) {
delete minimistoptions.arguments;
}
minimistOpts = buildMinimistOptions(minimistOpts);
minimistoptions = buildMinimistOptions(minimistoptions);
const pkg = opts.pkg;
const argv = minimist(opts.argv, minimistOpts);
let help = redent(trimNewlines((opts.help || '').replace(/\t+\n*$/, '')), 2);
if (minimistoptions['--']) {
minimistoptions.configuration = Object.assign({}, minimistoptions.configuration, {'populate--': true});
}
const {pkg} = options;
const argv = yargs(options.argv, minimistoptions);
let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2);
normalizePackageData(pkg);

@@ -60,5 +76,5 @@

let description = opts.description;
let {description} = options;
if (!description && description !== false) {
description = pkg.description;
({description} = pkg);
}

@@ -74,11 +90,11 @@

const showVersion = () => {
console.log(typeof opts.version === 'string' ? opts.version : pkg.version);
console.log(typeof options.version === 'string' ? options.version : pkg.version);
process.exit();
};
if (argv.version && opts.autoVersion) {
if (argv.version && options.autoVersion) {
showVersion();
}
if (argv.help && opts.autoHelp) {
if (argv.help && options.autoHelp) {
showHelp(0);

@@ -85,0 +101,0 @@ }

{
"name": "meow",
"version": "4.0.1",
"version": "5.0.0",
"description": "CLI app helper",

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

"engines": {
"node": ">=4"
"node": ">=6"
},

@@ -45,3 +45,2 @@ "scripts": {

"loud-rejection": "^1.0.0",
"minimist": "^1.1.3",
"minimist-options": "^3.0.1",

@@ -51,7 +50,8 @@ "normalize-package-data": "^2.3.4",

"redent": "^2.0.0",
"trim-newlines": "^2.0.0"
"trim-newlines": "^2.0.0",
"yargs-parser": "^10.0.0"
},
"devDependencies": {
"ava": "*",
"execa": "^0.8.0",
"execa": "^0.10.0",
"indent-string": "^3.0.0",

@@ -58,0 +58,0 @@ "xo": "*"

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

##### booleanDefault
Type: `boolean` `null` `undefined`<br>
Default: `false`
Value of `boolean` flags not defined in `argv`.
If set to `undefined` the flags not defined in `argv` will be excluded from the result.
The `default` value set in `boolean` flags take precedence over `booleanDefault`.
Example:
```js
const cli = meow(`
Usage
$ foo
Options
--rainbow, -r Include a rainbow
--unicorn, -r Include a unicorn
Examples
$ foo
🌈 unicorns 🌈
`, {
booleanDefault: undefined,
flags: {
rainbow: {
type: 'boolean',
default: true
alias: 'r'
},
unicorn: {
type: 'boolean',
default: false
alias: 'u'
},
cake: {
type: 'boolean',
alias: 'c'
}
}
});
/*
{
flags: {rainbow: true, unicorn: false},
}
*/
```
## Promises

@@ -179,0 +228,0 @@

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