New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cli-flags

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-flags - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

4

lib/errors/required_args.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const cli_1 = require("../cli");
const list_1 = require("cli-ux/lib/list");
class RequiredArgsError extends Error {

@@ -9,3 +9,3 @@ constructor(args) {

if (namedArgs.length) {
const list = cli_1.renderList(namedArgs.map(a => [a.name, a.description]));
const list = list_1.renderList(namedArgs.map(a => [a.name, a.description]));
msg += `:\n${list}`;

@@ -12,0 +12,0 @@ }

@@ -0,3 +1,3 @@

export { args, IArg } from './args';
export { parse } from './parse';
export { flags } from './flags';
export { args } from './args';
export { flags, Flag, ValueFlag } from './flags';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var args_1 = require("./args");
exports.args = args_1.args;
var parse_1 = require("./parse");

@@ -7,3 +9,3 @@ exports.parse = parse_1.parse;

exports.flags = flags_1.flags;
var args_1 = require("./args");
exports.args = args_1.args;
exports.Flag = flags_1.Flag;
exports.ValueFlag = flags_1.ValueFlag;

@@ -12,3 +12,10 @@ import { IArg } from './args';

output?: 'object' | 'array';
strict?: boolean;
}
export declare type InputOptions = IInputOptions & {
argv: string[];
flags: InputFlags;
args: InputArgs;
strict: boolean;
};
export interface IOutputArg {

@@ -15,0 +22,0 @@ type: 'arg';

@@ -60,3 +60,3 @@ "use strict";

const arg = argv.shift();
if (arg.startsWith('-')) {
if (parsingFlags && arg.startsWith('-')) {
// attempt to parse as arg

@@ -83,10 +83,3 @@ if (arg === '--') {

}
function parse(options) {
const input = Object.assign({ args: [], argv: process.argv.slice(2), flags: {} }, options);
setNames(input.flags);
const arr = parseArray(input);
validate_1.validate(input.args, input.flags, arr);
if (input.output === 'array') {
return arr;
}
function buildOutputFromArray(arr) {
return arr.reduce((obj, elem) => {

@@ -108,5 +101,4 @@ switch (elem.type) {

obj.argv.push(elem.input);
const { name } = input.args[elem.i];
if (name) {
obj.args[name] = elem.input;
if (elem.arg) {
obj.args[elem.arg.name] = elem.input;
}

@@ -122,2 +114,12 @@ break;

}
function parse(options) {
const input = Object.assign({ args: [], argv: process.argv.slice(2), flags: {} }, options, { strict: options.strict !== false });
setNames(input.flags);
const arr = parseArray(input);
validate_1.validate(input, arr);
if (input.output === 'array') {
return arr;
}
return buildOutputFromArray(arr);
}
exports.parse = parse;

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

import { InputArgs, InputFlags, OutputArray } from './parse';
export declare function validate(expectedArgs: InputArgs, expectedFlags: InputFlags, input: OutputArray): void;
import { InputOptions, OutputArray } from './parse';
export declare function validate(expected: InputOptions, input: OutputArray): void;

@@ -7,8 +7,8 @@ "use strict";

function validateArgs(expected, input) {
const maxArgs = expected.length;
if (input.length > maxArgs) {
const maxArgs = expected.args.length;
if (expected.strict && input.length > maxArgs) {
const extras = input.slice(maxArgs);
throw new unexpected_args_1.UnexpectedArgsError(extras);
}
const requiredArgs = expected.filter(a => a.required);
const requiredArgs = expected.args.filter(a => a.required);
const missingRequiredArgs = requiredArgs.slice(input.length);

@@ -20,4 +20,4 @@ if (missingRequiredArgs.length) {

function validateFlags(expected, input) {
const requiredFlags = Object.keys(expected)
.map(k => [k, expected[k]])
const requiredFlags = Object.keys(expected.flags)
.map(k => [k, expected.flags[k]])
.filter(([name, flag]) => flag.required);

@@ -31,8 +31,8 @@ for (const [name, flag] of requiredFlags) {

}
function validate(expectedArgs, expectedFlags, input) {
function validate(expected, input) {
const args = input.filter(a => a.type === 'arg');
const flags = input.filter(a => a.type === 'flag');
validateArgs(expectedArgs, args);
validateFlags(expectedFlags, flags);
validateArgs(expected, args);
validateFlags(expected, flags);
}
exports.validate = validate;
{
"name": "cli-flags",
"description": "basic CLI flag parser",
"version": "1.0.1",
"version": "1.0.2",
"author": "Jeff Dickey",
"bugs": "https://github.com/jdxcode/cli-flags/issues",
"dependencies": {
"@heroku/linewrap": "^1.0.0",
"lodash.maxby": "^4.6.0",
"lodash.padend": "^4.6.1"
"cli-ux": "^1.1.1"
},
"devDependencies": {
"@types/jest": "^20.0.8",
"@types/lodash.maxby": "^4.6.3",
"@types/lodash.padend": "^4.6.3",
"@types/node": "^8.0.28",

@@ -53,2 +49,3 @@ "husky": "^0.14.3",

"prettier --write",
"tslint --fix",
"git add",

@@ -55,0 +52,0 @@ "jest --bail --findRelatedTests"

@@ -32,2 +32,7 @@ cli-flags

console.log(`input arg: ${args.input}`)
// $ node example.js -f myinput --output-file=myexample.txt
// --force was set
// output file is: myexample.txt
// input arg: myinput
```
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