From 9208d314a6034729529ce7b9af67cbb4003ec52b Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 28 Sep 2022 10:50:46 -0600 Subject: [PATCH] chore: clean up --- package.json | 2 +- src/sfdxFlags.ts | 30 +++++++++++------------------- test/unit/sfdxFlags.test.ts | 4 ++-- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index f22c127..e253f6b 100644 --- a/package.json +++ b/package.json @@ -72,4 +72,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} diff --git a/src/sfdxFlags.ts b/src/sfdxFlags.ts index dae152a..43141fa 100644 --- a/src/sfdxFlags.ts +++ b/src/sfdxFlags.ts @@ -6,7 +6,7 @@ */ import { URL } from 'url'; -import { Flags as OclifFlags } from '@oclif/core'; +import { Flags as OclifFlags, Interfaces } from '@oclif/core'; import { Logger, LoggerLevel, Messages, sfdc, SfError } from '@salesforce/core'; import { Duration, toNumber } from '@salesforce/kit'; import { @@ -24,14 +24,6 @@ import { Omit, Optional, } from '@salesforce/ts-types'; -import { - BooleanFlag, - EnumFlagOptions, - Flag as OclifFlag, - FlagInput, - FlagOutput, - OptionFlag, -} from '@oclif/core/lib/interfaces'; import { Deprecation } from './ux'; Messages.importMessagesDirectory(__dirname); @@ -83,17 +75,17 @@ function toValidatorFn(validator?: unknown): (val: string) => boolean { function merge( kind: flags.Kind, - flag: OptionFlag, + flag: Interfaces.OptionFlag, describable: flags.Describable ): flags.Discriminated>; function merge( kind: flags.Kind, - flag: BooleanFlag, + flag: Interfaces.BooleanFlag, describable: flags.Describable ): flags.Discriminated>; function merge( kind: flags.Kind, - flag: OclifFlag, + flag: Interfaces.Flag, describable: flags.Describable ): flags.Discriminated> { if (has(flag, 'validate') && hasFunction(flag, 'parse')) { @@ -122,9 +114,9 @@ function option( } export namespace flags { - export type Any = Partial> & SfdxProperties; + export type Any = Partial> & SfdxProperties; export type Array = Option & { delimiter?: string }; - export type BaseBoolean = Partial>; + export type BaseBoolean = Partial>; export type Boolean = BaseBoolean & SfdxProperties; export type Bounds = { min?: T; max?: T }; export type Builtin = { type: 'builtin' } & Partial; @@ -133,9 +125,9 @@ export namespace flags { export type Describable = { description: string; longDescription?: string }; export type Discriminant = { kind: Kind }; export type Discriminated = T & Discriminant; - export type Enum = EnumFlagOptions & SfdxProperties; + export type Enum = Interfaces.EnumFlagOptions & SfdxProperties; export type Kind = keyof typeof flags; - export type Input = FlagInput; + export type Input = Interfaces.FlagInput; export type MappedArray = Omit, 'options'> & { map: (val: string) => T; options?: T[] }; // allow numeric bounds for back compat export type Milliseconds = Option & Bounds; @@ -143,8 +135,8 @@ export namespace flags { export type Minutes = Option & Bounds; export type Number = Option & NumericBounds; export type NumericBounds = Bounds; - export type Option = Partial> & SfdxProperties & Validatable; - export type Output = FlagOutput; + export type Option = Partial> & SfdxProperties & Validatable; + export type Output = Interfaces.FlagOutput; // allow numeric bounds for back compat export type Seconds = Option & Bounds; export type SfdxProperties = Describable & Deprecatable; @@ -220,7 +212,7 @@ function buildInteger(options: flags.Number): flags.Discriminated } function buildOption( - options: { parse: (val: string, ctx: unknown) => T } & flags.Option + options: { parse: (val: string, ctx: unknown) => Promise } & flags.Option ): flags.Discriminated> { return merge('option', OclifFlags.option(options), options); } diff --git a/test/unit/sfdxFlags.test.ts b/test/unit/sfdxFlags.test.ts index f7ddc2f..690ed21 100644 --- a/test/unit/sfdxFlags.test.ts +++ b/test/unit/sfdxFlags.test.ts @@ -94,12 +94,12 @@ describe('SfdxFlags', () => { myhelp: flags.help({ description: 'myhelp desc' }), myinteger: flags.integer({ description: 'myinteger desc' }), mystring: flags.string({ description: 'mystring desc' }), - // myoption: flags.option({ description: 'myoption desc', parse: (i: string) => i }), + myoption: flags.option({ description: 'myoption desc', parse: (i: string) => Promise.resolve(i) }), myversion: flags.version({ description: 'myversion desc' }), }, {} ); - expect(Object.keys(rv).length).to.equal(7); + expect(Object.keys(rv).length).to.equal(8); containsRequiredFlags(rv); expect(rv.mybool).to.include({ description: 'mybool desc', kind: 'boolean' }); expect(rv.myhelp).to.include({ description: 'myhelp desc', kind: 'help' });