Socket
Socket
Sign inDemoInstall

cac

Package Overview
Dependencies
Maintainers
3
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cac - npm Package Compare versions

Comparing version 6.1.3 to 6.2.0

10

dist/Command.js

@@ -9,5 +9,6 @@ "use strict";

class Command {
constructor(rawName, description) {
constructor(rawName, description, config = {}) {
this.rawName = rawName;
this.description = description;
this.config = config;
this.options = [];

@@ -18,3 +19,2 @@ this.aliasNames = [];

this.examples = [];
this.config = {};
}

@@ -29,2 +29,6 @@ usage(text) {

}
ignoreOptionDefaultValue() {
this.config.ignoreOptionDefaultValue = true;
return this;
}
version(version, customFlags = '-v, --version') {

@@ -101,3 +105,3 @@ this.versionNumber = version;

body: config.subCommands
.map(command => ` $ ${config.bin} ${command.name} --help`)
.map(command => ` $ ${config.bin}${command.name === '' ? '' : ` ${command.name}`} --help`)
.join('\n')

@@ -104,0 +108,0 @@ });

@@ -22,4 +22,4 @@ "use strict";

}
command(rawName, description) {
const command = new Command_1.default(rawName, description);
command(rawName, description, config) {
const command = new Command_1.default(rawName, description, config);
this.commands.push(command);

@@ -75,6 +75,3 @@ return command;

for (const command of this.commands) {
const minimistOptions = utils_1.getMinimistOptions([
...this.globalCommand.options,
...command.options
]);
const minimistOptions = utils_1.getMinimistOptions(this.globalCommand, command);
const { args, options, originalOptions } = this.minimist(argv.slice(2), minimistOptions);

@@ -98,6 +95,3 @@ const commandName = args[0];

if (command.name === '') {
const minimistOptions = utils_1.getMinimistOptions([
...this.globalCommand.options,
...command.options
]);
const minimistOptions = utils_1.getMinimistOptions(this.globalCommand, command);
const { args, options, originalOptions } = this.minimist(argv.slice(2), minimistOptions);

@@ -116,3 +110,3 @@ this.matchedCommand = command;

}
const globalMinimistOptions = utils_1.getMinimistOptions(this.globalCommand.options);
const globalMinimistOptions = utils_1.getMinimistOptions(this.globalCommand);
const { args, options } = this.minimist(argv.slice(2), globalMinimistOptions);

@@ -119,0 +113,0 @@ this.args = args;

@@ -31,12 +31,21 @@ "use strict";

};
exports.getMinimistOptions = (options) => {
exports.getMinimistOptions = (globalCommand, subCommand) => {
const options = [
...globalCommand.options,
...(subCommand ? subCommand.options : [])
];
const ignoreDefault = subCommand && subCommand.config.ignoreOptionDefaultValue
? subCommand.config.ignoreOptionDefaultValue
: globalCommand.config.ignoreOptionDefaultValue;
return {
default: options.reduce((res, option) => {
if (option.config.default !== undefined) {
// Only need to set the default value of the first name
// Since minimist will automatically do the rest for alias names
res[option.names[0]] = option.config.default;
}
return res;
}, {}),
default: ignoreDefault
? {}
: options.reduce((res, option) => {
if (option.config.default !== undefined) {
// Only need to set the default value of the first name
// Since minimist will automatically do the rest for alias names
res[option.names[0]] = option.config.default;
}
return res;
}, {}),
boolean: options

@@ -43,0 +52,0 @@ .filter(option => option.isBoolean)

{
"name": "cac",
"version": "6.1.3",
"version": "6.2.0",
"description": "Simple yet powerful framework for building command-line apps.",

@@ -5,0 +5,0 @@ "repository": {

@@ -26,3 +26,3 @@ <img width="945" alt="2017-07-26 9 27 05" src="https://user-images.githubusercontent.com/8784712/28623641-373450f4-7249-11e7-854d-1b076dab274d.png">

- [CLI Instance](#cli-instance)
- [cli.command(name, description)](#clicommandname-description)
- [cli.command(name, description, config?)](#clicommandname-description-config)
- [cli.option(name, description, config?)](#clioptionname-description-config)

@@ -240,3 +240,3 @@ - [cli.parse(argv?)](#cliparseargv)

#### cli.command(name, description)
#### cli.command(name, description, config?)

@@ -247,2 +247,7 @@ - Type: `(name: string, description: string) => Command`

The option also accepts a third argument `config` for addtional command config:
- `config.allowUnknownOptions`: `boolean` Allow unknown options in this command.
- `config.ignoreOptionDefaultValue`: `boolean` Don't use the options's default value in parsed options, only display them in help message.
#### cli.option(name, description, config?)

@@ -254,3 +259,3 @@

The option also accepts a third argument `config` for addtional config:
The option also accepts a third argument `config` for addtional option config:

@@ -257,0 +262,0 @@ - `config.default`: Default value for the option.

@@ -19,2 +19,3 @@ import Option, { OptionConfig } from './Option';

allowUnknownOptions?: boolean;
ignoreOptionDefaultValue?: boolean;
}

@@ -26,2 +27,3 @@ declare type HelpCallback = (sections: HelpSection[]) => void;

description: string;
config: CommandConfig;
options: Option[];

@@ -35,7 +37,7 @@ aliasNames: string[];

examples: CommandExample[];
config: CommandConfig;
helpCallback?: HelpCallback;
constructor(rawName: string, description: string);
constructor(rawName: string, description: string, config?: CommandConfig);
usage(text: string): this;
allowUnknownOptions(): this;
ignoreOptionDefaultValue(): this;
version(version: string, customFlags?: string): this;

@@ -75,2 +77,2 @@ example(example: CommandExample): this;

}
export { HelpCallback, CommandExample };
export { HelpCallback, CommandExample, CommandConfig };
/// <reference types="node" />
import { EventEmitter } from 'events';
import Command, { HelpCallback, CommandExample } from './Command';
import Command, { CommandConfig, HelpCallback, CommandExample } from './Command';
import { OptionConfig } from './Option';

@@ -32,3 +32,3 @@ interface ParsedArgv {

usage(text: string): this;
command(rawName: string, description: string): Command;
command(rawName: string, description: string, config?: CommandConfig): Command;
option(rawName: string, description: string, config?: OptionConfig): this;

@@ -35,0 +35,0 @@ help(callback?: HelpCallback): this;

@@ -1,2 +0,2 @@

import Option from './Option';
import Command from './Command';
export declare const removeBrackets: (v: string) => string;

@@ -8,3 +8,3 @@ export declare const findAllBrackets: (v: string) => {

}[];
export declare const getMinimistOptions: (options: Option[]) => {
export declare const getMinimistOptions: (globalCommand: Command, subCommand?: Command | undefined) => {
default: {};

@@ -11,0 +11,0 @@ boolean: string[];

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc