Skip to content

Commit

Permalink
refactor: remove cli v3 feature flag (#10356)
Browse files Browse the repository at this point in the history
* refactor: remove cli v3 feature flag

* test: ut
  • Loading branch information
jayzhang authored Nov 14, 2023
1 parent 3e9abbd commit c28270f
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 105 deletions.
8 changes: 1 addition & 7 deletions packages/cli/src/commands/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
VersionState,
assembleError,
getHashedEnv,
isCliV3Enabled,
isUserCancelError,
} from "@microsoft/teamsfx-core";
import { cloneDeep, pick } from "lodash";
Expand Down Expand Up @@ -207,12 +206,7 @@ class CLIEngine {
// 6. version check
const inputs = getSystemInputs(context.optionValues.projectPath as string);
inputs.ignoreEnvInfo = true;
const skipCommands = [
"new",
"sample",
"upgrade",
...(isCliV3Enabled() ? ["update", "package", "publish", "validate"] : []),
];
const skipCommands = ["new", "sample", "upgrade", "update", "package", "publish", "validate"];
if (!skipCommands.includes(context.command.name) && context.optionValues.projectPath) {
const core = getFxCore();
const res = await core.projectVersionCheck(inputs);
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/commands/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import { CLICommand } from "@microsoft/teamsfx-api";
import { accountLoginCommand } from "./accountLogin";
import { accountLogoutCommand } from "./accountLogout";
import { accountShowCommand } from "./accountShow";
import { isCliV3Enabled } from "@microsoft/teamsfx-core";

export const accountCommand: CLICommand = {
name: isCliV3Enabled() ? "auth" : "account",
aliases: isCliV3Enabled() ? ["account"] : ["auth"],
name: "auth",
aliases: ["account"],
description: "Manage Microsoft 365 and Azure accounts.",
commands: [accountShowCommand, accountLoginCommand, accountLogoutCommand],
};
8 changes: 4 additions & 4 deletions packages/cli/src/commands/models/accountShow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand, err, ok } from "@microsoft/teamsfx-api";
import { AppStudioScopes, isCliV3Enabled } from "@microsoft/teamsfx-core";
import { AppStudioScopes } from "@microsoft/teamsfx-core";
import { TextType, colorize } from "../../colorize";
import AzureTokenProvider, { getAzureProvider } from "../../commonlib/azureLogin";
import AzureTokenCIProvider from "../../commonlib/azureLoginCI";
Expand Down Expand Up @@ -84,8 +84,8 @@ class AccountUtils {
export const accountUtils = new AccountUtils();

export const accountShowCommand: CLICommand = {
name: isCliV3Enabled() ? "list" : "show",
aliases: isCliV3Enabled() ? ["show"] : ["list"],
name: "list",
aliases: ["show"],
description: "Display all connected Microsoft 365 and Azure accounts.",
telemetry: {
event: TelemetryEvent.AccountShow,
Expand Down Expand Up @@ -114,7 +114,7 @@ export const accountShowCommand: CLICommand = {

if (m365Status.status !== signedIn && azureStatus.status !== signedIn) {
logger.info(
`Use \`${process.env.TEAMSFX_CLI_BIN_NAME} account login azure\` or \`${process.env.TEAMSFX_CLI_BIN_NAME} account login m365\` to log in to Azure or Microsoft 365 account.`
`Use \`${process.env.TEAMSFX_CLI_BIN_NAME} auth login azure\` or \`${process.env.TEAMSFX_CLI_BIN_NAME} auth login m365\` to log in to Azure or Microsoft 365 account.`
);
}
return ok(undefined);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/models/m365LaunchInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export const m365LaunchInfoCommand: CLICommand = {
],
examples: [
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} m365 launchinfo --title-id U_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} launchinfo --title-id U_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
description: "Get launch information of the acquired M365 App by Title ID",
},
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} m365 launchinfo --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} launchinfo --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
description: "Get launch information of the acquired M365 App by Manifest ID",
},
],
Expand Down
19 changes: 5 additions & 14 deletions packages/cli/src/commands/models/m365Sideloading.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand, LogLevel, err, ok } from "@microsoft/teamsfx-api";
import {
PackageService,
isCliV3Enabled,
serviceEndpoint,
serviceScope,
} from "@microsoft/teamsfx-core";
import { PackageService, serviceEndpoint, serviceScope } from "@microsoft/teamsfx-core";
import { logger } from "../../commonlib/logger";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { ArgumentConflictError, MissingRequiredOptionError } from "../../error";
Expand Down Expand Up @@ -51,8 +46,8 @@ class M365Utils {
export const m365utils = new M365Utils();

export const m365SideloadingCommand: CLICommand = {
name: isCliV3Enabled() ? "install" : "sideloading",
aliases: isCliV3Enabled() ? ["sideloading"] : ["install"],
name: "install",
aliases: ["sideloading"],
description: "Sideload a given application package across Microsoft 365.",
options: [
{
Expand All @@ -68,16 +63,12 @@ export const m365SideloadingCommand: CLICommand = {
],
examples: [
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} ${
isCliV3Enabled() ? "install" : "m365 sideloading"
} --file-path appPackage.zip`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} install --file-path appPackage.zip`,
description:
"Sideload the application package with JSON-based manifest to Teams, Outlook, and the Microsoft 365 app.",
},
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} ${
isCliV3Enabled() ? "install" : "m365 sideloading"
} --xml-path manifest.xml`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} install --xml-path manifest.xml`,
description:
"Sideload the Outlook add-in application package with XML-based manifest to Outlook.",
},
Expand Down
12 changes: 5 additions & 7 deletions packages/cli/src/commands/models/m365Unacquire.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand, LogLevel, err, ok } from "@microsoft/teamsfx-api";
import { PackageService, isCliV3Enabled } from "@microsoft/teamsfx-core";
import { PackageService } from "@microsoft/teamsfx-core";
import { logger } from "../../commonlib/logger";
import { MissingRequiredOptionError } from "../../error";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { m365utils, sideloadingServiceEndpoint } from "./m365Sideloading";

const commandName = isCliV3Enabled() ? "uninstall" : "unacquire";

export const m365UnacquireCommand: CLICommand = {
name: commandName,
aliases: isCliV3Enabled() ? ["unacquire"] : ["uninstall"],
name: "uninstall",
aliases: ["unacquire"],
description: "Remove an acquired M365 App.",
options: [
{
Expand All @@ -27,11 +25,11 @@ export const m365UnacquireCommand: CLICommand = {
],
examples: [
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} m365 ${commandName} --title-id U_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --title-id U_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
description: "Remove the acquired M365 App by Title ID",
},
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} m365 ${commandName} --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} uninstall --manifest-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`,
description: "Remove the acquired M365 App by Manifest ID",
},
],
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/src/commands/models/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
import { CLICommand } from "@microsoft/teamsfx-api";
import { permissionGrantCommand } from "./permissionGrant";
import { permissionStatusCommand } from "./permissionStatus";
import { isCliV3Enabled } from "@microsoft/teamsfx-core";

export const permissionCommand: CLICommand = {
name: isCliV3Enabled() ? "collaborator" : "permission",
aliases: isCliV3Enabled() ? ["permission"] : ["collaborator"],
name: "collaborator",
aliases: ["permission"],
description:
"Check, grant and list permissions for who can access and manage Microsoft Teams application and Microsoft Entra application.",
commands: [permissionStatusCommand, permissionGrantCommand],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/models/permissionGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const permissionGrantCommand: CLICommand = {
},
examples: [
{
command: `${process.env.TEAMSFX_CLI_BIN_NAME} permission grant -i false --teams-manifest-file ./appPackage/manifest.json --env dev --email other@email.com`,
command: `${process.env.TEAMSFX_CLI_BIN_NAME} collaborator grant -i false --teams-manifest-file ./appPackage/manifest.json --env dev --email other@email.com`,
description:
"Grant permission for another Microsoft 365 account to collaborate on the Microsoft Teams app.",
},
Expand Down
52 changes: 21 additions & 31 deletions packages/cli/src/commands/models/root.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand, ok } from "@microsoft/teamsfx-api";
import { logger } from "../../commonlib/logger";
import { FooterText } from "../../constants";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { getVersion } from "../../utils";
import { helper } from "../helper";
import { accountCommand } from "./account";
import { addCommand } from "./add";
import { getCreateCommand } from "./create";
import { deployCommand } from "./deploy";
import { entraAppCommand } from "./entraAppUpdate";
import { envCommand } from "./env";
import { m365Command } from "./m365";
import { packageCommand } from "./package";
import { listCommand } from "./list";
import { m365LaunchInfoCommand } from "./m365LaunchInfo";
import { m365SideloadingCommand } from "./m365Sideloading";
import { m365UnacquireCommand } from "./m365Unacquire";
import { permissionCommand } from "./permission";
import { previewCommand } from "./preview";
import { provisionCommand } from "./provision";
import { publishCommand } from "./publish";
import { updateCommand } from "./update";
import { upgradeCommand } from "./upgrade";
import { validateCommand } from "./validate";
import { listCommand } from "./list";
import { helper } from "../helper";
import { logger } from "../../commonlib/logger";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { teamsappUpdateCommand } from "./teamsapp/update";
import { teamsappValidateCommand } from "./teamsapp/validate";
import { teamsappDoctorCommand } from "./teamsapp/doctor";
import { teamsappPackageCommand } from "./teamsapp/package";
import { teamsappPublishCommand } from "./teamsapp/publish";
import { isCliV3Enabled } from "@microsoft/teamsfx-core";
import { teamsappDoctorCommand } from "./teamsapp/doctor";
import { entraAppCommand } from "./entraAppUpdate";
import { m365SideloadingCommand } from "./m365Sideloading";
import { m365UnacquireCommand } from "./m365Unacquire";
import { m365LaunchInfoCommand } from "./m365LaunchInfo";
import { teamsappUpdateCommand } from "./teamsapp/update";
import { teamsappValidateCommand } from "./teamsapp/validate";
import { upgradeCommand } from "./upgrade";

export const helpCommand: CLICommand = {
name: "help",
Expand Down Expand Up @@ -59,19 +53,15 @@ export const rootCommand: CLICommand = {
upgradeCommand,
listCommand,
helpCommand,
...(isCliV3Enabled()
? [
teamsappUpdateCommand,
teamsappValidateCommand,
teamsappPackageCommand,
teamsappPublishCommand,
teamsappDoctorCommand,
entraAppCommand,
m365SideloadingCommand,
m365UnacquireCommand,
m365LaunchInfoCommand,
]
: [packageCommand, updateCommand, validateCommand, publishCommand, m365Command]),
teamsappUpdateCommand,
teamsappValidateCommand,
teamsappPackageCommand,
teamsappPublishCommand,
teamsappDoctorCommand,
entraAppCommand,
m365SideloadingCommand,
m365UnacquireCommand,
m365LaunchInfoCommand,
],
sortCommands: true,
options: [
Expand Down
12 changes: 5 additions & 7 deletions packages/cli/tests/unit/engine.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ import {
} from "@microsoft/teamsfx-core";
import { assert } from "chai";
import "mocha";
import mockedEnv, { RestoreFn } from "mocked-env";
import * as sinon from "sinon";
import * as activate from "../../src/activate";
import { getFxCore, resetFxCore } from "../../src/activate";
import { engine } from "../../src/commands/engine";
import { start } from "../../src/commands/index";
import {
listTemplatesCommand,
listSamplesCommand,
listTemplatesCommand,
m365SideloadingCommand,
} from "../../src/commands/models";
import { getCreateCommand } from "../../src/commands/models/create";
import { createSampleCommand } from "../../src/commands/models/createSample";
import { rootCommand } from "../../src/commands/models/root";
import { logger } from "../../src/commonlib/logger";
import { CliTelemetryReporter } from "../../src/commonlib/telemetry";
import {
InvalidChoiceError,
UnknownArgumentError,
Expand All @@ -40,10 +40,8 @@ import {
} from "../../src/error";
import * as main from "../../src/index";
import CliTelemetry from "../../src/telemetry/cliTelemetry";
import { getVersion } from "../../src/utils";
import { UserSettings } from "../../src/userSetttings";
import { CliTelemetryReporter } from "../../src/commonlib/telemetry";
import * as common from "@microsoft/teamsfx-core";
import { getVersion } from "../../src/utils";

describe("CLI Engine", () => {
const sandbox = sinon.createSandbox();
Expand All @@ -62,8 +60,8 @@ describe("CLI Engine", () => {
assert.equal(result.cmd.name, createSampleCommand.name);
assert.deepEqual(result.remainingArgs, []);
});
it("should find m365 command alias", async () => {
const result = engine.findCommand(rootCommand, ["m365", "sideloading"]);
it("should find sideloading command alias", async () => {
const result = engine.findCommand(rootCommand, ["sideloading"]);
assert.equal(result.cmd.name, m365SideloadingCommand.name);
assert.deepEqual(result.remainingArgs, []);
});
Expand Down
4 changes: 0 additions & 4 deletions packages/fx-core/src/common/featureFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ export function isApiCopilotPluginEnabled(): boolean {
return isFeatureFlagEnabled(FeatureFlagName.ApiCopilotPlugin, false) && isCopilotPluginEnabled();
}

export function isCliV3Enabled(): boolean {
return isFeatureFlagEnabled("TEAMSFX_CLI_V3", false);
}

export function enableTestToolByDefault(): boolean {
return isFeatureFlagEnabled(FeatureFlagName.TestTool, true);
}
Expand Down
23 changes: 1 addition & 22 deletions packages/fx-core/tests/common/featureFlags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import chaiAsPromised from "chai-as-promised";
import mockedEnv, { RestoreFn } from "mocked-env";

import { FeatureFlagName } from "../../src/common/constants";
import {
initializePreviewFeatureFlags,
isApiKeyEnabled,
isCliV3Enabled,
} from "../../src/common/featureFlags";
import { initializePreviewFeatureFlags, isApiKeyEnabled } from "../../src/common/featureFlags";

chai.use(chaiAsPromised);

Expand All @@ -34,23 +30,6 @@ describe("featureFlags", () => {
});
});

describe("isCliV3Enabled()", () => {
let mockedEnvRestore: RestoreFn = () => {};
afterEach(() => {
mockedEnvRestore();
});
it("is true", async () => {
mockedEnvRestore = mockedEnv({ TEAMSFX_CLI_V3: "true" });
const res = isCliV3Enabled();
chai.assert.isTrue(res);
});
it("is false", async () => {
mockedEnvRestore = mockedEnv({ TEAMSFX_CLI_V3: "false" });
const res = isCliV3Enabled();
chai.assert.isFalse(res);
});
});

describe("isApiKeyEnabled()", () => {
let mockedEnvRestore: RestoreFn = () => {};
afterEach(() => {
Expand Down

0 comments on commit c28270f

Please sign in to comment.