From 24e08c7acccd80a1a9b87df9d1307f71422035fd Mon Sep 17 00:00:00 2001 From: Necroskillz Date: Sat, 22 Aug 2015 23:00:53 +0200 Subject: [PATCH] Update minimist definition to 1.1.3 - Add indexer to ParsedArgs - Add new options and options types --- minimist/minimist-tests.ts | 15 +++++++++++++++ minimist/minimist.d.ts | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/minimist/minimist-tests.ts b/minimist/minimist-tests.ts index 1f714fd3e..2266d2739 100644 --- a/minimist/minimist-tests.ts +++ b/minimist/minimist-tests.ts @@ -9,8 +9,12 @@ var strArr: string[]; var args: string[]; var obj: minimist.ParsedArgs; var opts: Opts; +var arg: any; +opts.string = str; opts.string = strArr; +opts.boolean = true; +opts.boolean = str; opts.boolean = strArr; opts.alias = { foo: strArr @@ -21,8 +25,19 @@ opts.default = { opts.default = { foo: num }; +opts.unknown = (arg: string) => { + if(/xyz/.test(arg)){ + return true; + } + + return false; +}; +opts.stopEarly = true; +opts['--'] = true; obj = minimist(); obj = minimist(strArr); obj = minimist(strArr, opts); var remainingArgCount = obj._.length; + +arg = obj['foo']; diff --git a/minimist/minimist.d.ts b/minimist/minimist.d.ts index 98d0f37a8..abbc5f028 100644 --- a/minimist/minimist.d.ts +++ b/minimist/minimist.d.ts @@ -1,6 +1,6 @@ -// Type definitions for minimist 0.0.8 +// Type definitions for minimist 1.1.3 // Project: https://github.com/substack/minimist -// Definitions by: Bart van der Schoor +// Definitions by: Bart van der Schoor , Necroskillz // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module 'minimist' { @@ -10,18 +10,26 @@ declare module 'minimist' { export interface Opts { // a string or array of strings argument names to always treat as strings // string?: string; - string?: string[]; + string?: string|string[]; // a string or array of strings to always treat as booleans // boolean?: string; - boolean?: string[]; + boolean?: boolean|string|string[]; // an object mapping string names to strings or arrays of string argument names to use // alias?: {[key:string]: string}; alias?: {[key:string]: string[]}; // an object mapping string argument names to default values default?: {[key:string]: any}; + // when true, populate argv._ with everything after the first non-option + stopEarly?: boolean; + // a function which is invoked with a command line parameter not defined in the opts configuration object. + // If the function returns false, the unknown option is not added to argv + unknown?: (arg: string) => boolean; + // when true, populate argv._ with everything before the -- and argv['--'] with everything after the -- + '--'?: boolean; } export interface ParsedArgs { + [arg: string]: any; _: string[]; } }