Skip to content

Commit

Permalink
refactor: split cli string files into three and extract cli descripti…
Browse files Browse the repository at this point in the history
…on strings into string files (#11127)

* refactor: split cli string files into three

* refactor: extract strings from commands

* refactor: extract strings from commands

* refactor: clean up

* refactor: clean up

* test: ut
  • Loading branch information
jayzhang authored Mar 21, 2024
1 parent 150ebf1 commit 6bd8cb8
Show file tree
Hide file tree
Showing 50 changed files with 311 additions and 291 deletions.
3 changes: 2 additions & 1 deletion packages/cli/src/commands/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import { CLICommandOption } from "@microsoft/teamsfx-api";
import { commands } from "../resource";

export const ProjectFolderOption: CLICommandOption = {
name: "folder",
Expand Down Expand Up @@ -68,7 +69,7 @@ export const IgnoreKeysOption: CLICommandOption = {
export const ListFormatOption: CLICommandOption = {
name: "format",
shortName: "f",
description: "Specifies the format of the results.",
description: commands["list.templates"].options.format,
type: "string",
choices: ["table", "json"],
default: "table",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
// Licensed under the MIT license.

import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { accountLoginCommand } from "./accountLogin";
import { accountLogoutCommand } from "./accountLogout";
import { accountShowCommand } from "./accountShow";

export const accountCommand: CLICommand = {
name: "auth",
aliases: ["account"],
description: "Manage Microsoft 365 and Azure accounts.",
description: commands.auth.description,
commands: [accountShowCommand, accountLoginCommand, accountLogoutCommand],
};
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/accountLogin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { accountLoginAzureCommand } from "./accountLoginAzure";
import { accountLoginM365Command } from "./accountLoginM365";

export const accountLoginCommand: CLICommand = {
name: "login",
description: "Log in to Microsoft 365 or Azure account.",
description: commands["auth.login"].description,
commands: [accountLoginM365Command, accountLoginAzureCommand],
};
13 changes: 7 additions & 6 deletions packages/cli/src/commands/models/accountLoginAzure.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { UserError, err, ok, CLICommand } from "@microsoft/teamsfx-api";
import { CLICommand, UserError, err, ok } from "@microsoft/teamsfx-api";
import AzureTokenProvider from "../../commonlib/azureLogin";
import {
codeFlowLoginFormat,
loginComponent,
servicePrincipalLoginFormat,
usageError,
} from "../../commonlib/common/constant";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { accountUtils } from "./accountShow";

export const accountLoginAzureCommand: CLICommand = {
name: "azure",
description: "Log in to Azure account.",
description: commands["auth.login.azure"].description,
options: [
{
name: "tenant",
description: "Authenticate with a specific Microsoft Entra tenant.",
description: commands["auth.login.azure"].options["tenant"],
type: "string",
default: "",
},
{
name: "service-principal",
description: "Authenticate Azure with a credential representing a service principal",
description: commands["auth.login.azure"].options["service-principal"],
type: "boolean",
default: false,
},
{
name: "username",
shortName: "u",
description: "Client ID for service principal",
description: commands["auth.login.azure"].options.username,
type: "string",
default: "",
},
{
name: "password",
shortName: "p",
description: "Provide client secret or a pem file with key and public certificate.",
description: commands["auth.login.azure"].options.password,
type: "string",
default: "",
},
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/accountLoginM365.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.
import { CLICommand, ok } from "@microsoft/teamsfx-api";
import M365TokenProvider from "../../commonlib/m365Login";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { accountUtils } from "./accountShow";

export const accountLoginM365Command: CLICommand = {
name: "m365",
description: "Log in to Microsoft 365 account.",
description: commands["auth.login.m365"].description,
telemetry: {
event: TelemetryEvent.AccountLoginM365,
},
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/commands/models/accountLogout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import { CLICommand, ok } from "@microsoft/teamsfx-api";
import AzureTokenProvider from "../../commonlib/azureLogin";
import { logger } from "../../commonlib/logger";
import M365TokenProvider from "../../commonlib/m365Login";
import { cliSource } from "../../constants";
import { commands, strings } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";

export const accountLogoutCommand: CLICommand = {
name: "logout",
description: "Log out of Microsoft 365 or Azure account.",
description: commands["auth.logout"].description,
arguments: [
{
type: "string",
name: "service",
description: "Azure or Microsoft 365.",
description: commands["auth.logout"].arguments.service,
choices: ["azure", "m365"],
required: true,
},
Expand All @@ -30,19 +30,19 @@ export const accountLogoutCommand: CLICommand = {
ctx.telemetryProperties.service = "azure";
const result = await AzureTokenProvider.signout();
if (result) {
logger.info(`[${cliSource}] Successfully signed out of Azure.`);
logger.info(strings["account.logout.azure"]);
} else {
logger.error(`[${cliSource}] Failed to sign out of Azure.`);
logger.error(strings["account.logout.azure.fail"]);
}
break;
}
case "m365": {
ctx.telemetryProperties.service = "m365";
const result = await M365TokenProvider.signout();
if (result) {
logger.info(`[${cliSource}] Successfully signed out of Microsoft 365.`);
logger.info(strings["account.logout.m365"]);
} else {
logger.error(`[${cliSource}] Failed to sign out of Microsoft 365.`);
logger.error(strings["account.logout.m365.fail"]);
}
break;
}
Expand Down
9 changes: 4 additions & 5 deletions packages/cli/src/commands/models/accountShow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { checkIsOnline } from "../../commonlib/codeFlowLogin";
import { signedIn } from "../../commonlib/common/constant";
import { logger } from "../../commonlib/logger";
import M365TokenProvider from "../../commonlib/m365Login";
import * as constants from "../../constants";
import { strings } from "../../resource";
import { commands, strings } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";

class AccountUtils {
Expand All @@ -37,7 +36,7 @@ class AccountUtils {
return Promise.resolve(true);
} else {
if (commandType === "login") {
logger.outputError(`[${constants.cliSource}] Failed to sign in to Microsoft 365.`);
logger.outputError(strings["account.login.m365.fail"]);
}
}
return Promise.resolve(result !== undefined);
Expand Down Expand Up @@ -70,7 +69,7 @@ class AccountUtils {
return Promise.resolve(true);
} else {
if (commandType === "login") {
logger.outputError(`[${constants.cliSource}] Failed to sign in to Azure.`);
logger.outputError(strings["account.login.azure.fail"]);
}
}
return Promise.resolve(result !== undefined);
Expand All @@ -86,7 +85,7 @@ export const accountUtils = new AccountUtils();
export const accountShowCommand: CLICommand = {
name: "list",
aliases: ["show"],
description: "Display all connected Microsoft 365 and Azure accounts.",
description: commands["auth.show"].description,
telemetry: {
event: TelemetryEvent.AccountShow,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/models/add.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { addSPFxWebpartCommand } from "./addSPFxWebpart";

export const addCommand: CLICommand = {
name: "add",
description: "Add feature to your Microsoft Teams application.",
description: commands.add.description,
commands: [addSPFxWebpartCommand],
};
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/addSPFxWebpart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import { CLICommand, Stage } from "@microsoft/teamsfx-api";
import { SPFxAddWebpartInputs, SPFxAddWebpartOptions } from "@microsoft/teamsfx-core";
import { getFxCore } from "../../activate";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { ProjectFolderOption } from "../common";

export const addSPFxWebpartCommand: CLICommand = {
name: "spfx-web-part",
description: "Auto-hosted SPFx web part tightly integrated with Microsoft Teams.",
description: commands["add.spfx-web-part"].description,
options: [...SPFxAddWebpartOptions, ProjectFolderOption],
telemetry: {
event: TelemetryEvent.AddWebpart,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/models/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import {
CreateProjectOptions,
MeArchitectureOptions,
QuestionNames,
isApiCopilotPluginEnabled,
} 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 { commands } from "../../resource";
import { TelemetryEvent, TelemetryProperty } from "../../telemetry/cliTelemetryEvents";
import { createSampleCommand } from "./createSample";

Expand All @@ -49,7 +49,7 @@ function adjustOptions(options: CLICommandOption[]) {
export function getCreateCommand(): CLICommand {
return {
name: "new",
description: "Create a new Microsoft Teams application.",
description: commands.create.description,
options: [...adjustOptions(CreateProjectOptions)],
examples: [
{
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/src/commands/models/createSample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ import {
} 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 { commands } from "../../resource";
import { TelemetryEvent, TelemetryProperty } from "../../telemetry/cliTelemetryEvents";
import * as path from "path";

export const createSampleCommand: CLICommand = {
name: "sample",
description: "Create an app from existing sample.",
description: commands["create.sample"].description,
arguments: CreateSampleProjectArguments,
options: CreateSampleProjectOptions,
telemetry: {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/models/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
// Licensed under the MIT license.
import { CLICommand, CLIContext, InputsWithProjectPath } from "@microsoft/teamsfx-api";
import { getFxCore } from "../../activate";
import { strings } from "../../resource";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import {
ConfigFilePathOption,
EnvOption,
IgnoreLoadEnvOption,
ProjectFolderOption,
ConfigFilePathOption,
} from "../common";

export const deployCommand: CLICommand = {
name: "deploy",
description: strings.command.deploy.description,
description: commands.deploy.description,
options: [EnvOption, ProjectFolderOption, IgnoreLoadEnvOption, ConfigFilePathOption],
telemetry: {
event: TelemetryEvent.Deploy,
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/commands/models/entraAppUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.
import { CLICommand, Inputs } from "@microsoft/teamsfx-api";
import { getFxCore } from "../../activate";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { EntraAppManifestFileOption, EnvOption, ProjectFolderOption } from "../common";

export const entraAppUpdateCommand: CLICommand = {
name: "update",
description: "Update the Microsoft Entra app in the current application.",
description: commands["entra-app.update"].description,
options: [EntraAppManifestFileOption, EnvOption, ProjectFolderOption],
telemetry: {
event: TelemetryEvent.UpdateAadApp,
Expand All @@ -24,6 +25,6 @@ export const entraAppUpdateCommand: CLICommand = {

export const entraAppCommand: CLICommand = {
name: "entra-app",
description: "Manage the Microsoft Entra app in the current application.",
description: commands["entra-app"].description,
commands: [entraAppUpdateCommand],
};
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/env.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { CLICommand } from "@microsoft/teamsfx-api";
import { commands } from "../../resource";
import { envAddCommand } from "./envAdd";
import { envListCommand } from "./envList";
import { envResetCommand } from "./envReset";

export const envCommand: CLICommand = {
name: "env",
description: "Manage environments.",
description: commands.env.description,
commands: [envAddCommand, envListCommand, envResetCommand],
};
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/envAdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import {
} from "@microsoft/teamsfx-core";
import { getFxCore } from "../../activate";
import { WorkspaceNotSupported } from "../../cmds/preview/errors";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { ProjectFolderOption } from "../common";

export const envAddCommand: CLICommand = {
name: "add",
description: "Add a new environment by copying from the specified environment.",
description: commands["env.add"].description,
options: [...CreateEnvOptions, ProjectFolderOption],
arguments: CreateEnvArguments,
telemetry: {
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/envList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { envUtil, isValidProjectV3 } from "@microsoft/teamsfx-core";
import os from "os";
import { WorkspaceNotSupported } from "../../cmds/preview/errors";
import { logger } from "../../commonlib/logger";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { ProjectFolderOption } from "../common";

export const envListCommand: CLICommand = {
name: "list",
description: "List all environments.",
description: commands["env.list"].description,
options: [ProjectFolderOption],
telemetry: {
event: TelemetryEvent.GrantPermission,
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/commands/models/envReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Licensed under the MIT license.
import { CLICommand, ok } from "@microsoft/teamsfx-api";
import { envUtil } from "@microsoft/teamsfx-core";
import { commands } from "../../resource";
import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents";
import { EnvFileOption, EnvOption, IgnoreKeysOption, ProjectFolderOption } from "../common";

export const envResetCommand: CLICommand = {
name: "reset",
description: "Reset environment file.",
description: commands["env.reset"].description,
options: [EnvOption, EnvFileOption, IgnoreKeysOption, ProjectFolderOption],
telemetry: {
event: TelemetryEvent.ResetEnvironment,
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/src/commands/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export * from "./envList";
export * from "./list";
export * from "./listTemplates";
export * from "./listSamples";
export * from "./m365";
export * from "./m365LaunchInfo";
export * from "./m365Sideloading";
export * from "./m365Unacquire";
Expand All @@ -30,8 +29,5 @@ export * from "./preview";
export * from "./provision";
export * from "./publish";
export * from "./root";
export * from "./update";
export * from "./updateAadApp";
export * from "./updateTeamsApp";
export * from "./upgrade";
export * from "./validate";
Loading

0 comments on commit 6bd8cb8

Please sign in to comment.