diff --git a/packages/cli/src/commands/models/create.ts b/packages/cli/src/commands/models/create.ts index 43830a2c69..489840f083 100644 --- a/packages/cli/src/commands/models/create.ts +++ b/packages/cli/src/commands/models/create.ts @@ -4,47 +4,44 @@ import { CLICommand, CLICommandOption, CLIContext, - CLIStringOption, + Platform, err, ok, } from "@microsoft/teamsfx-api"; import { + CapabilityOptions, + CliQuestionName, CreateProjectInputs, CreateProjectOptions, QuestionNames, isCopilotPluginEnabled, - CliQuestionName, - copilotPluginOptionIds, } from "@microsoft/teamsfx-core"; import chalk from "chalk"; import { assign } from "lodash"; +import * as path from "path"; import * as uuid from "uuid"; import { getFxCore } from "../../activate"; import { logger } from "../../commonlib/logger"; import { TelemetryEvent, TelemetryProperty } from "../../telemetry/cliTelemetryEvents"; import { createSampleCommand } from "./createSample"; -import * as path from "path"; -function filterOptionsIfNotCopilotPlugin(options: CLICommandOption[]) { +function adjustOptions(options: CLICommandOption[]) { if (!isCopilotPluginEnabled()) { - // filter out copilot-plugin in capability question - const capability = options.find( - (c: CLICommandOption) => c.name === CliQuestionName.Capability - ) as CLIStringOption; - if (capability.choices) { - capability.choices = capability.choices.filter( - (c: string) => !copilotPluginOptionIds.includes(c) - ); - } - + //skip copilot plugin options if copilot plugin is not enabled const copilotPluginQuestionNames = [ QuestionNames.ApiSpecLocation.toString(), QuestionNames.OpenAIPluginDomain.toString(), QuestionNames.ApiOperation.toString(), ]; - options = options.filter((option) => !copilotPluginQuestionNames.includes(option.name)); } + for (const option of options) { + if (option.type === "string" && option.name === CliQuestionName.Capability) { + // use dynamic options for capability question + option.choices = CapabilityOptions.all({ platform: Platform.CLI }).map((o) => o.id); + break; + } + } return options; } @@ -52,7 +49,7 @@ export function getCreateCommand(): CLICommand { return { name: "new", description: "Create a new Microsoft Teams application.", - options: [...filterOptionsIfNotCopilotPlugin(CreateProjectOptions)], + options: [...adjustOptions(CreateProjectOptions)], examples: [ { command: "teamsfx new -c notification -t timer-functions -l typescript -n myapp -i false", diff --git a/packages/fx-core/src/question/create.ts b/packages/fx-core/src/question/create.ts index c81618a6c2..4986ce5f8b 100644 --- a/packages/fx-core/src/question/create.ts +++ b/packages/fx-core/src/question/create.ts @@ -409,6 +409,9 @@ export class CapabilityOptions { ]; } + /** + * static capability list, which does not depend on any feature flags + */ static staticAll(inputs?: Inputs): OptionItem[] { const capabilityOptions = [ ...CapabilityOptions.bots(inputs), @@ -422,17 +425,19 @@ export class CapabilityOptions { return capabilityOptions; } + /** + * dynamic capability list, which depends on feature flags + */ static all(inputs?: Inputs): OptionItem[] { - // teamsfx list templates const capabilityOptions = [ ...CapabilityOptions.bots(inputs), ...CapabilityOptions.tabs(), ...CapabilityOptions.mes(), + CapabilityOptions.SearchMe(), ]; if (isCopilotPluginEnabled()) { capabilityOptions.push(...CapabilityOptions.copilotPlugins()); } - return capabilityOptions; } diff --git a/packages/fx-core/tests/question/create.test.ts b/packages/fx-core/tests/question/create.test.ts index 2aade4f389..7c98c47b7b 100644 --- a/packages/fx-core/tests/question/create.test.ts +++ b/packages/fx-core/tests/question/create.test.ts @@ -590,11 +590,6 @@ describe("scaffold question", () => { questions.push(question.name); await callFuncs(question, inputs); if (question.name === QuestionNames.Capabilities) { - const select = question as SingleSelectQuestion; - const staticOptions = select.staticOptions; - assert.isTrue(staticOptions.length === 16); - const options = await select.dynamicOptions!(inputs); - assert.isTrue(options.length === 12); return ok({ type: "success", result: CapabilityOptions.notificationBot().id }); } else if (question.name === QuestionNames.BotTrigger) { return ok({ type: "success", result: NotificationTriggerOptions.appService().id }); @@ -636,17 +631,8 @@ describe("scaffold question", () => { if (question.name === QuestionNames.Runtime) { return ok({ type: "success", result: RuntimeOptions.DotNet().id }); } else if (question.name === QuestionNames.Capabilities) { - const select = question as SingleSelectQuestion; - const options = await select.dynamicOptions!(inputs); - assert.isTrue(options.length === 12); return ok({ type: "success", result: CapabilityOptions.notificationBot().id }); } else if (question.name === QuestionNames.BotTrigger) { - const select = question as SingleSelectQuestion; - const options = await select.dynamicOptions!(inputs); - assert.deepEqual(options, [ - NotificationTriggerOptions.appServiceForVS(), - ...NotificationTriggerOptions.functionsTriggers(), - ]); return ok({ type: "success", result: NotificationTriggerOptions.appServiceForVS().id }); } else if (question.name === QuestionNames.ProgrammingLanguage) { return ok({ type: "success", result: "javascript" }); @@ -863,9 +849,6 @@ describe("scaffold question", () => { questions.push(question.name); await callFuncs(question, inputs); if (question.name === QuestionNames.Capabilities) { - const select = question as SingleSelectQuestion; - const options = await select.dynamicOptions!(inputs); - assert.isTrue(options.length === 15); return ok({ type: "success", result: CapabilityOptions.copilotPluginNewApi().id }); } else if (question.name === QuestionNames.ProgrammingLanguage) { return ok({ type: "success", result: "javascript" });