@anycli/parser
Advanced tools
Comparing version 3.1.0 to 3.1.1
@@ -0,1 +1,10 @@ | ||
<a name="3.1.1"></a> | ||
## [3.1.1](https://github.com/anycli/parser/compare/56be8c82683f4b657bdf05ade5db54390abb5d67...v3.1.1) (2018-02-03) | ||
### Bug Fixes | ||
* add context fo parse ([85c1e06](https://github.com/anycli/parser/commit/85c1e06)) | ||
* append context to default ([50bf003](https://github.com/anycli/parser/commit/50bf003)) | ||
<a name="3.1.0"></a> | ||
@@ -2,0 +11,0 @@ # [3.1.0](https://github.com/anycli/parser/compare/b5a7d6d5e4df2f270a900f83e01b8ac7836cd556...v3.1.0) (2018-02-03) |
@@ -18,3 +18,3 @@ import { AlphabetLowercase, AlphabetUppercase } from './alphabet'; | ||
env?: string; | ||
parse(input: I): T; | ||
parse(input: I, context: any): T; | ||
}; | ||
@@ -21,0 +21,0 @@ export declare type IBooleanFlag<T> = IFlagBase<T, boolean> & { |
@@ -11,2 +11,3 @@ import * as args from './args'; | ||
strict?: boolean; | ||
context?: any; | ||
}; | ||
@@ -13,0 +14,0 @@ export declare function parse<TFlags, TArgs extends { |
@@ -14,2 +14,3 @@ "use strict"; | ||
argv, | ||
context: options.context, | ||
args: (options.args || []).map((a) => deps_1.deps.args.newArg(a)), | ||
@@ -16,0 +17,0 @@ flags: Object.assign({ color: deps_1.deps.flags.defaultFlags.color }, ((options.flags || {}))), |
@@ -30,2 +30,3 @@ import { Arg } from './args'; | ||
strict: boolean; | ||
context: any; | ||
} | ||
@@ -37,2 +38,3 @@ export declare class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']>, TArgs extends OutputArgs<T['args']>> { | ||
private readonly booleanFlags; | ||
private readonly context; | ||
constructor(input: T); | ||
@@ -39,0 +41,0 @@ parse(): { |
@@ -23,2 +23,3 @@ "use strict"; | ||
this.raw = []; | ||
this.context = input.context || {}; | ||
this.argv = input.argv.slice(0); | ||
@@ -135,3 +136,3 @@ this._setNames(); | ||
} | ||
flags[token.flag] = flag.parse(flags[token.flag]); | ||
flags[token.flag] = flag.parse(flags[token.flag], this.context); | ||
} | ||
@@ -143,3 +144,3 @@ else { | ||
} | ||
const value = flag.parse ? flag.parse(input) : input; | ||
const value = flag.parse ? flag.parse(input, this.context) : input; | ||
if (flag.multiple) { | ||
@@ -161,7 +162,7 @@ flags[token.flag] = flags[token.flag] || []; | ||
if (input) | ||
flags[k] = flag.parse(input); | ||
flags[k] = flag.parse(input, this.context); | ||
} | ||
if (!flags[k] && flag.default) { | ||
if (typeof flag.default === 'function') { | ||
flags[k] = flag.default({ options: flag, flags }); | ||
flags[k] = flag.default(Object.assign({ options: flag, flags }, this.context)); | ||
} | ||
@@ -168,0 +169,0 @@ else { |
{ | ||
"name": "@anycli/parser", | ||
"description": "arg and flag parser for anycli", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"author": "Jeff Dickey @jdxcode", | ||
@@ -6,0 +6,0 @@ "bugs": "https://github.com/anycli/parser/issues", |
31418
713