Comparing version 3.2.0-rc.10 to 3.2.0-rc.11
@@ -140,2 +140,11 @@ /// <reference types="node" /> | ||
}; | ||
/** | ||
* An all-in-one helper that simultaneously instantiate a CLI and immediately | ||
* executes it. All parameters are optional except the command classes and | ||
* will be filled by sensible values for the current environment (for example | ||
* the argv argument will default to `process.argv`, etc). | ||
* | ||
* Just like `Cli#runExit`, this function will set the `process.exitCode` value | ||
* before returning. | ||
*/ | ||
export declare function runExit<Context extends BaseContext = BaseContext>(commandClasses: RunCommandNoContext<Context>): Promise<void>; | ||
@@ -149,2 +158,11 @@ export declare function runExit<Context extends BaseContext = BaseContext>(commandClasses: RunCommand<Context>, context: RunContext<Context>): Promise<void>; | ||
export declare function runExit<Context extends BaseContext = BaseContext>(options: Partial<CliOptions>, commandClasses: RunCommand<Context>, argv: Array<string>, context: RunContext<Context>): Promise<void>; | ||
/** | ||
* An all-in-one helper that simultaneously instantiate a CLI and immediately | ||
* executes it. All parameters are optional except the command classes and | ||
* will be filled by sensible values for the current environment (for example | ||
* the argv argument will default to `process.argv`, etc). | ||
* | ||
* Unlike `runExit`, this function won't set the `process.exitCode` value | ||
* before returning. | ||
*/ | ||
export declare function run<Context extends BaseContext = BaseContext>(commandClasses: RunCommandNoContext<Context>): Promise<number>; | ||
@@ -151,0 +169,0 @@ export declare function run<Context extends BaseContext = BaseContext>(commandClasses: RunCommand<Context>, context: RunContext<Context>): Promise<number>; |
@@ -65,2 +65,8 @@ import { LooseTest } from 'typanion'; | ||
}; | ||
/** | ||
* Base abstract class for CLI commands. The main thing to remember is to | ||
* declare an async `execute` member function that will be called when the | ||
* command is invoked from the CLI, and optionally a `paths` property to | ||
* declare the set of paths under which the command should be exposed. | ||
*/ | ||
export declare abstract class Command<Context extends BaseContext = BaseContext> { | ||
@@ -67,0 +73,0 @@ /** |
@@ -27,2 +27,8 @@ 'use strict'; | ||
/** | ||
* Base abstract class for CLI commands. The main thing to remember is to | ||
* declare an async `execute` member function that will be called when the | ||
* command is invoked from the CLI, and optionally a `paths` property to | ||
* declare the set of paths under which the command should be exposed. | ||
*/ | ||
class Command { | ||
@@ -29,0 +35,0 @@ constructor() { |
@@ -0,4 +1,6 @@ | ||
import { StrictValidator } from "typanion"; | ||
import { GeneralOptionFlags, CommandOptionReturn, WithArity } from "./utils"; | ||
export declare type ArrayFlags<Arity extends number = 1> = GeneralOptionFlags & { | ||
export declare type ArrayFlags<T, Arity extends number = 1> = GeneralOptionFlags & { | ||
arity?: Arity; | ||
validator?: StrictValidator<unknown, Array<T>>; | ||
}; | ||
@@ -13,6 +15,6 @@ /** | ||
*/ | ||
export declare function Array<Arity extends number = 1>(descriptor: string, opts: ArrayFlags<Arity> & { | ||
export declare function Array<T = string, Arity extends number = 1>(descriptor: string, opts: ArrayFlags<T, Arity> & { | ||
required: true; | ||
}): CommandOptionReturn<Array<WithArity<string, Arity>>>; | ||
export declare function Array<Arity extends number = 1>(descriptor: string, opts?: ArrayFlags<Arity>): CommandOptionReturn<Array<WithArity<string, Arity>> | undefined>; | ||
export declare function Array<Arity extends number = 1>(descriptor: string, initialValue: Array<WithArity<string, Arity>>, opts?: Omit<ArrayFlags<Arity>, 'required'>): CommandOptionReturn<Array<WithArity<string, Arity>>>; | ||
}): CommandOptionReturn<Array<WithArity<T, Arity>>>; | ||
export declare function Array<T = string, Arity extends number = 1>(descriptor: string, opts?: ArrayFlags<T, Arity>): CommandOptionReturn<Array<WithArity<T, Arity>> | undefined>; | ||
export declare function Array<T = string, Arity extends number = 1>(descriptor: string, initialValue: Array<WithArity<string, Arity>>, opts?: Omit<ArrayFlags<T, Arity>, 'required'>): CommandOptionReturn<Array<WithArity<T, Arity>>>; |
@@ -23,2 +23,3 @@ 'use strict'; | ||
transformer(builder, key, state) { | ||
let usedName; | ||
let currentValue = typeof initialValue !== `undefined` | ||
@@ -30,6 +31,12 @@ ? [...initialValue] | ||
continue; | ||
usedName = name; | ||
currentValue = currentValue !== null && currentValue !== void 0 ? currentValue : []; | ||
currentValue.push(value); | ||
} | ||
return currentValue; | ||
if (typeof currentValue !== `undefined`) { | ||
return advanced_options_utils.applyValidator(usedName !== null && usedName !== void 0 ? usedName : key, currentValue, opts.validator); | ||
} | ||
else { | ||
return currentValue; | ||
} | ||
}, | ||
@@ -36,0 +43,0 @@ }); |
@@ -13,3 +13,5 @@ import { StrictValidator } from 'typanion'; | ||
export declare type Tuple<Type, Arity extends number> = Arity extends Arity ? number extends Arity ? Array<Type> : TupleOf<Type, Arity, []> : never; | ||
export declare type WithArity<Type, Arity extends number> = Arity extends 0 ? boolean : Arity extends 1 ? Type : number extends Arity ? boolean | Type | Tuple<Type, Arity> : Tuple<Type, Arity>; | ||
export declare type WithArity<Type extends { | ||
length?: number; | ||
}, Arity extends number> = number extends Type['length'] ? Arity extends 0 ? boolean : Arity extends 1 ? Type : number extends Arity ? boolean | Type | Tuple<Type, Arity> : Tuple<Type, Arity> : Type; | ||
export declare type CommandOption<T> = { | ||
@@ -24,4 +26,6 @@ [isOptionSymbol]: true; | ||
export declare function rerouteArguments<A, B>(a: A | B | undefined, b: B): [Exclude<A, B> | undefined, B]; | ||
export declare function cleanValidationError(message: string, lowerCase?: boolean): string; | ||
export declare function cleanValidationError(message: string, { mergeName }?: { | ||
mergeName?: boolean; | ||
}): string; | ||
export declare function formatError(message: string, errors: Array<string>): UsageError; | ||
export declare function applyValidator<U, V>(name: string, value: U, validator?: StrictValidator<unknown, V>): U; |
@@ -22,11 +22,17 @@ 'use strict'; | ||
} | ||
function cleanValidationError(message, lowerCase = false) { | ||
let cleaned = message.replace(/^\.: /, ``); | ||
if (lowerCase) | ||
cleaned = cleaned[0].toLowerCase() + cleaned.slice(1); | ||
return cleaned; | ||
function cleanValidationError(message, { mergeName = false } = {}) { | ||
const match = message.match(/^([^:]+): (.*)$/m); | ||
if (!match) | ||
return `validation failed`; | ||
let [, path, line] = match; | ||
if (mergeName) | ||
line = line[0].toLowerCase() + line.slice(1); | ||
line = path !== `.` || !mergeName | ||
? `${path.replace(/^\.(\[|$)/, `$1`)}: ${line}` | ||
: `: ${line}`; | ||
return line; | ||
} | ||
function formatError(message, errors$1) { | ||
if (errors$1.length === 1) { | ||
return new errors.UsageError(`${message}: ${cleanValidationError(errors$1[0], true)}`); | ||
return new errors.UsageError(`${message}${cleanValidationError(errors$1[0], { mergeName: true })}`); | ||
} | ||
@@ -33,0 +39,0 @@ else { |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "3.2.0-rc.10", | ||
"version": "3.2.0-rc.11", | ||
"main": "lib/advanced/index", | ||
@@ -27,3 +27,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"typanion": "^3.3.1" | ||
"typanion": "^3.8.0" | ||
}, | ||
@@ -38,2 +38,3 @@ "peerDependencies": { | ||
"@types/chai-as-promised": "^7.1.2", | ||
"@types/lodash": "^4.14.179", | ||
"@types/mocha": "^7.0.2", | ||
@@ -52,2 +53,3 @@ "@types/node": "^14.0.13", | ||
"get-stream": "^5.1.0", | ||
"lodash": "^4.17.21", | ||
"mocha": "^8.0.1", | ||
@@ -54,0 +56,0 @@ "rollup": "^2.16.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
223033
5163
26
Updatedtypanion@^3.8.0