diff --git a/src/command.ts b/src/command.ts index 46065dc8..f938cf12 100644 --- a/src/command.ts +++ b/src/command.ts @@ -128,25 +128,25 @@ export default abstract class Command { return cmd._run(argv) } - protected static _globalFlags: Interfaces.FlagInput + protected static _globalFlags: Interfaces.FlagInput - static get globalFlags(): Interfaces.FlagInput { + static get globalFlags(): Interfaces.FlagInput { return this._globalFlags } - static set globalFlags(flags: Interfaces.FlagInput) { + static set globalFlags(flags: Interfaces.FlagInput) { this._globalFlags = Object.assign({}, this.globalFlags, flags) this.flags = {} // force the flags setter to run } /** A hash of flags for the command */ - protected static _flags: Interfaces.FlagInput + protected static _flags: Interfaces.FlagInput - static get flags(): Interfaces.FlagInput { + static get flags(): Interfaces.FlagInput { return this._flags } - static set flags(flags: Interfaces.FlagInput) { + static set flags(flags: Interfaces.FlagInput) { this._flags = Object.assign({}, this._flags ?? {}, this.globalFlags, flags) } diff --git a/src/interfaces/parser.ts b/src/interfaces/parser.ts index fecb8c3f..63bbf605 100644 --- a/src/interfaces/parser.ts +++ b/src/interfaces/parser.ts @@ -49,6 +49,7 @@ export interface CLIParseErrorOptions { export type OutputArgs = { [name: string]: any } export type OutputFlags = { [P in keyof T]: any } + export type ParserOutput = any, GFlags extends OutputFlags = any, TArgs extends OutputArgs = any> = { // Add in global flags so that they show up in the types // This is necessary because there's no easy way to optionally return @@ -200,4 +201,4 @@ export type CompletableOptionFlag = OptionFlag & { export type CompletableFlag = BooleanFlag | CompletableOptionFlag -export type FlagInput = { [P in keyof T]: CompletableFlag } +export type FlagInput = { [P in keyof T]: CompletableFlag } diff --git a/src/parser/index.ts b/src/parser/index.ts index 6ad741f1..dfbf21ed 100644 --- a/src/parser/index.ts +++ b/src/parser/index.ts @@ -1,10 +1,8 @@ -// tslint:disable interface-over-type-literal - import * as args from './args' import Deps from './deps' import * as flags from './flags' import {Parser} from './parse' -import {Input, ParserOutput} from '../interfaces' +import {FlagInput, Input, ParserOutput} from '../interfaces' import * as Validate from './validate' export {args} export {flags} @@ -23,8 +21,8 @@ export async function parse, strict: options.strict !== false, } const parser = new Parser(input)