Skip to content

Commit

Permalink
refactor: Switch to union type for input definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
dlhck committed May 9, 2024
1 parent 82eb0a2 commit 5b45350
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { addJobQueueCommand } from '../job-queue/add-job-queue';
import { addServiceCommand } from '../service/add-service';
import { addUiExtensionsCommand } from '../ui-extensions/add-ui-extensions';

import { inputDefinitions } from './add-plugin.input-options';
import { inputDefinitions } from './add-plugin.input-definitions';
import { generatePlugin } from './add-plugin.service';
import { GeneratePluginOptions } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from 'commander';
import { enrichProgramWithInputOptions } from '../../../shared/program-builder';
import { analyzeProject } from '../../../shared/shared-prompts';

import { inputDefinitions } from './add-plugin.input-options';
import { inputDefinitions } from './add-plugin.input-definitions';
import { generatePlugin } from './add-plugin.service';
import { GeneratePluginOptions } from './types';

Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/shared/input-option-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,26 @@ export class InputOptionSelectChoice {
hint?: string;
}

export class InputOptionDefinition {
export class DefaultInputOptionDefinition {
name: string;
shortFlag: string;
longName: string;
type: InputOptionType;
choices?: InputOptionSelectChoice[];
help?: string;
description?: string;
prompt?: string;
description: string;
prompt: string;
defaultValue?: (currentOptions: Record<string, any>, project: Project) => any;
required?: boolean;
validate?: (value: any) => string | void;
transform?: (value: any) => any;
}

export class SelectInputOptionDefinition extends DefaultInputOptionDefinition {
choices?: InputOptionSelectChoice[];
}

export type InputOptionDefinition = DefaultInputOptionDefinition | SelectInputOptionDefinition;

export class InputDefinitions {
options: InputOptionDefinition[];
}

0 comments on commit 5b45350

Please sign in to comment.