Skip to content

Commit

Permalink
fix: get good typing for array flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Dec 19, 2022
1 parent 87401b9 commit 1e6ae3f
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import { Flags } from '@oclif/core';
import { Lifecycle, Messages } from '@salesforce/core';
import { OptionFlagProps } from '@oclif/core/lib/interfaces';
import { orgApiVersionFlag } from './flags/orgApiVersion';
import { optionalOrgFlag, requiredHubFlag, requiredOrgFlag } from './flags/orgFlags';

Expand Down Expand Up @@ -78,20 +77,20 @@ export const requiredHubFlagWithDeprecations = requiredHubFlag({
required: true,
});

export type ArrayWithDeprecationOptions = {
multiple?: true;
parse?: undefined;
};
/**
* @deprecated
*/
export const arrayWithDeprecation = (options: Partial<Omit<OptionFlagProps, 'multiple' | 'parse'>>) =>
Flags.string({
// populate passed options
...options,
// overlay those options we own
multiple: true,
parse: async (input: string) => {
const inputParts = input.split(',').map((i) => i.trim());
if (inputParts.length > 1) {
await Lifecycle.getInstance().emitWarning(messages.getMessage('warning.arrayInputFormat'));
}
return inputParts;
},
});
export const arrayWithDeprecation = Flags.custom<string[], ArrayWithDeprecationOptions>({
multiple: true,
parse: async (input: string) => {
const inputParts = input.split(',').map((i) => i.trim());
if (inputParts.length > 1) {
await Lifecycle.getInstance().emitWarning(messages.getMessage('warning.arrayInputFormat'));
}
return inputParts;
},
});

0 comments on commit 1e6ae3f

Please sign in to comment.