Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Sep 28, 2022
1 parent 9a20f1f commit 9208d31
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@
"publishConfig": {
"access": "public"
}
}
}
30 changes: 11 additions & 19 deletions src/sfdxFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -83,17 +75,17 @@ function toValidatorFn(validator?: unknown): (val: string) => boolean {

function merge<T>(
kind: flags.Kind,
flag: OptionFlag<T | undefined>,
flag: Interfaces.OptionFlag<T | undefined>,
describable: flags.Describable
): flags.Discriminated<flags.Option<T>>;
function merge<T>(
kind: flags.Kind,
flag: BooleanFlag<T>,
flag: Interfaces.BooleanFlag<T>,
describable: flags.Describable
): flags.Discriminated<flags.Boolean<T>>;
function merge<T>(
kind: flags.Kind,
flag: OclifFlag<T>,
flag: Interfaces.Flag<T>,
describable: flags.Describable
): flags.Discriminated<flags.Any<T>> {
if (has(flag, 'validate') && hasFunction(flag, 'parse')) {
Expand Down Expand Up @@ -122,9 +114,9 @@ function option<T>(
}

export namespace flags {
export type Any<T> = Partial<OclifFlag<T>> & SfdxProperties;
export type Any<T> = Partial<Interfaces.Flag<T>> & SfdxProperties;
export type Array<T = string> = Option<T[]> & { delimiter?: string };
export type BaseBoolean<T> = Partial<BooleanFlag<T>>;
export type BaseBoolean<T> = Partial<Interfaces.BooleanFlag<T>>;
export type Boolean<T> = BaseBoolean<T> & SfdxProperties;
export type Bounds<T> = { min?: T; max?: T };
export type Builtin = { type: 'builtin' } & Partial<SfdxProperties>;
Expand All @@ -133,18 +125,18 @@ export namespace flags {
export type Describable = { description: string; longDescription?: string };
export type Discriminant = { kind: Kind };
export type Discriminated<T> = T & Discriminant;
export type Enum<T> = EnumFlagOptions<T> & SfdxProperties;
export type Enum<T> = Interfaces.EnumFlagOptions<T> & SfdxProperties;
export type Kind = keyof typeof flags;
export type Input<T extends FlagOutput> = FlagInput<T>;
export type Input<T extends Interfaces.FlagOutput> = Interfaces.FlagInput<T>;
export type MappedArray<T> = Omit<flags.Array<T>, 'options'> & { map: (val: string) => T; options?: T[] };
// allow numeric bounds for back compat
export type Milliseconds = Option<Duration> & Bounds<Duration | number>;
// allow numeric bounds for back compat
export type Minutes = Option<Duration> & Bounds<Duration | number>;
export type Number = Option<number> & NumericBounds;
export type NumericBounds = Bounds<number>;
export type Option<T> = Partial<OptionFlag<T>> & SfdxProperties & Validatable;
export type Output = FlagOutput;
export type Option<T> = Partial<Interfaces.OptionFlag<T>> & SfdxProperties & Validatable;
export type Output = Interfaces.FlagOutput;
// allow numeric bounds for back compat
export type Seconds = Option<Duration> & Bounds<Duration | number>;
export type SfdxProperties = Describable & Deprecatable;
Expand Down Expand Up @@ -220,7 +212,7 @@ function buildInteger(options: flags.Number): flags.Discriminated<flags.Number>
}

function buildOption<T>(
options: { parse: (val: string, ctx: unknown) => T } & flags.Option<T>
options: { parse: (val: string, ctx: unknown) => Promise<T> } & flags.Option<T>
): flags.Discriminated<flags.Option<T>> {
return merge('option', OclifFlags.option(options), options);
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sfdxFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand Down

0 comments on commit 9208d31

Please sign in to comment.