diff --git a/readme.az.common.md b/readme.az.common.md index 29f0e9744..7a6527ce6 100644 --- a/readme.az.common.md +++ b/readme.az.common.md @@ -2,6 +2,8 @@ ``` yaml $(az) extension-mode: experimental +# customize library used in extension. azure.cli.core by default +# cli-core-lib: azure.cli.core cli: naming: diff --git a/src/plugins/azgenerator/Generator.ts b/src/plugins/azgenerator/Generator.ts index 7f5ff49bd..612031866 100644 --- a/src/plugins/azgenerator/Generator.ts +++ b/src/plugins/azgenerator/Generator.ts @@ -25,7 +25,7 @@ import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit" import { GenerateAzureCliTestInit } from "./TemplateAzureCliTestInit" export async function GenerateAll(model: CodeModelAz, - generateReport: any, debug: boolean) { + generateReport: any, debug: boolean, cliCoreLib: string) { let files: any = {}; await model.init(); @@ -37,10 +37,10 @@ export async function GenerateAll(model: CodeModelAz, let pathTop = ""; let path = "azext_" + model.Extension_NameUnderscored + "/"; - files[path + "generated/_params.py"] = GenerateAzureCliParams(model, debug); - files[path + "generated/commands.py"] = GenerateAzureCliCommands(model); - files[path + "generated/custom.py"] = GenerateAzureCliCustom(model); - files[path + "generated/_client_factory.py"] = GenerateAzureCliClientFactory(model); + files[path + "generated/_params.py"] = GenerateAzureCliParams(model, debug, cliCoreLib); + files[path + "generated/commands.py"] = GenerateAzureCliCommands(model, cliCoreLib); + files[path + "generated/custom.py"] = GenerateAzureCliCustom(model, cliCoreLib); + files[path + "generated/_client_factory.py"] = GenerateAzureCliClientFactory(model, cliCoreLib); files[path + "generated/_validators.py"] = GenerateAzureCliValidators(model); files[path + "generated/action.py"] = GenerateAzureCliActions(model); files[path + "generated/_help.py"] = GenerateAzureCliHelp(model, debug); @@ -54,7 +54,7 @@ export async function GenerateAll(model: CodeModelAz, files[path + "manual/__init__.py"] = GenerateNamespaceInit(model); files[path + "action.py"] = GenerateTopLevelImport(model, "action"); files[path + "custom.py"] = GenerateTopLevelImport(model, "custom"); - files[path + "__init__.py"] = GenerateAzureCliInit(model); + files[path + "__init__.py"] = GenerateAzureCliInit(model, cliCoreLib); files[pathTop + "HISTORY.rst"] = GenerateAzureCliHistory(model); files[pathTop + "README.md"] = GenerateAzureCliReadme(model); files[pathTop + "setup.cfg"] = GenerateAzureCliSetupCfg(model); diff --git a/src/plugins/azgenerator/TemplateAzureCliClientFactory.ts b/src/plugins/azgenerator/TemplateAzureCliClientFactory.ts index 0d6d01e31..04466c696 100644 --- a/src/plugins/azgenerator/TemplateAzureCliClientFactory.ts +++ b/src/plugins/azgenerator/TemplateAzureCliClientFactory.ts @@ -7,14 +7,14 @@ import { CodeModelAz } from "./CodeModelAz" import { HeaderGenerator } from "./Header"; import { isNullOrUndefined } from "util"; -export function GenerateAzureCliClientFactory(model: CodeModelAz): string[] { +export function GenerateAzureCliClientFactory(model: CodeModelAz, cliCoreLib: string): string[] { let header: HeaderGenerator = new HeaderGenerator(); var output: string[] = header.getLines(); model.SelectFirstCommandGroup(); output.push(""); output.push(""); output.push("def cf_" + model.Extension_NameUnderscored + "_cl(cli_ctx, *_):"); - output.push(" from azure.cli.core.commands.client_factory import get_mgmt_service_client"); + output.push(" from " + cliCoreLib + ".commands.client_factory import get_mgmt_service_client"); output.push(" from ..vendored_sdks." + model.PythonOperationsName + " import " + model.PythonMgmtClient); if (!isNullOrUndefined(model.Extension_ClientAuthenticationPolicy)) { diff --git a/src/plugins/azgenerator/TemplateAzureCliCommands.ts b/src/plugins/azgenerator/TemplateAzureCliCommands.ts index 6ecad3865..6ec32def3 100644 --- a/src/plugins/azgenerator/TemplateAzureCliCommands.ts +++ b/src/plugins/azgenerator/TemplateAzureCliCommands.ts @@ -10,13 +10,13 @@ import { isNullOrUndefined } from "util"; import { SchemaType } from "@azure-tools/codemodel"; let showCommandFunctionName = undefined; -export function GenerateAzureCliCommands(model: CodeModelAz): string[] { +export function GenerateAzureCliCommands(model: CodeModelAz, cliCoreLib: string): string[] { let header: HeaderGenerator = new HeaderGenerator(); // this can't be currently reproduced header.disableTooManyStatements = true; header.disableTooManyLocals = true; - header.addFromImport("azure.cli.core.commands", ["CliCommandType"]); + header.addFromImport(cliCoreLib + ".commands", ["CliCommandType"]); let output: string[] = [] output.push(""); diff --git a/src/plugins/azgenerator/TemplateAzureCliCustom.ts b/src/plugins/azgenerator/TemplateAzureCliCustom.ts index 84856e449..fe4f6f413 100644 --- a/src/plugins/azgenerator/TemplateAzureCliCustom.ts +++ b/src/plugins/azgenerator/TemplateAzureCliCustom.ts @@ -9,7 +9,7 @@ import { Capitalize, ToCamelCase, ToMultiLine, ToPythonString } from '../../util import { CodeModelAz } from "./CodeModelAz"; import { HeaderGenerator } from "./Header"; -export function GenerateAzureCliCustom(model: CodeModelAz): string[] { +export function GenerateAzureCliCustom(model: CodeModelAz, cliCoreLib: string): string[] { let header: HeaderGenerator = new HeaderGenerator(); header.disableTooManyLines = true; @@ -29,7 +29,7 @@ export function GenerateAzureCliCustom(model: CodeModelAz): string[] { } if(required['nowait']) { - header.addFromImport("azure.cli.core.util", ["sdk_no_wait"]); + header.addFromImport(cliCoreLib + ".util", ["sdk_no_wait"]); } if(required['disableUnusedArgument']) { diff --git a/src/plugins/azgenerator/TemplateAzureCliInit.ts b/src/plugins/azgenerator/TemplateAzureCliInit.ts index f30490cf1..e05924ea0 100644 --- a/src/plugins/azgenerator/TemplateAzureCliInit.ts +++ b/src/plugins/azgenerator/TemplateAzureCliInit.ts @@ -7,9 +7,9 @@ import { CodeModelAz } from "./CodeModelAz" import { HeaderGenerator } from "./Header"; import { ToMultiLine } from "../../utils/helper" -export function GenerateAzureCliInit(model: CodeModelAz): string[] { +export function GenerateAzureCliInit(model: CodeModelAz, cliCoreLib: string): string[] { let header: HeaderGenerator = new HeaderGenerator(); - header.addFromImport("azure.cli.core", ["AzCommandsLoader"]); + header.addFromImport(cliCoreLib, ["AzCommandsLoader"]); var output: string[] = header.getLines(); output.push("from azext_" + model.Extension_NameUnderscored + ".generated._help import helps # pylint: disable=unused-import"); @@ -22,7 +22,7 @@ export function GenerateAzureCliInit(model: CodeModelAz): string[] { output.push("class " + model.Extension_NameClass + "CommandsLoader(AzCommandsLoader):"); output.push(""); output.push(" def __init__(self, cli_ctx=None):"); - output.push(" from azure.cli.core.commands import CliCommandType"); + output.push(" from " + cliCoreLib + ".commands import CliCommandType"); output.push(" from azext_" + model.Extension_NameUnderscored + ".generated._client_factory import cf_" + model.Extension_NameUnderscored + "_cl"); output.push(" " + model.Extension_NameUnderscored + "_custom = CliCommandType("); output.push(" operations_tmpl='azext_" + model.Extension_NameUnderscored + ".custom#{}',"); diff --git a/src/plugins/azgenerator/TemplateAzureCliParams.ts b/src/plugins/azgenerator/TemplateAzureCliParams.ts index 208111bab..49b54bb1b 100644 --- a/src/plugins/azgenerator/TemplateAzureCliParams.ts +++ b/src/plugins/azgenerator/TemplateAzureCliParams.ts @@ -20,7 +20,7 @@ let hasLocationValidator = false; let hasTags = false; let actions: string[] = []; -export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean): string[] { +export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean, cliCoreLib: string): string[] { var output_args: string[] = []; output_args.push(""); @@ -65,7 +65,7 @@ export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean): stri if (hasResourceGroup) parameterImports.push("resource_group_name_type"); if (hasLocation) parameterImports.push("get_location_type"); - header.addFromImport("azure.cli.core.commands.parameters", parameterImports); + header.addFromImport(cliCoreLib + ".commands.parameters", parameterImports); let validatorImports: string[] = []; if (hasLocationValidator) { validatorImports.push("get_default_location_from_resource_group"); @@ -74,7 +74,7 @@ export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean): stri validatorImports.push("validate_file_or_dict"); } if (validatorImports.length > 0) { - header.addFromImport('azure.cli.core.commands.validators', validatorImports); + header.addFromImport(cliCoreLib + '.commands.validators', validatorImports); } if (hasActions) { diff --git a/src/plugins/azgenerator/azgenerator.ts b/src/plugins/azgenerator/azgenerator.ts index 83ba52604..4a3f1095d 100644 --- a/src/plugins/azgenerator/azgenerator.ts +++ b/src/plugins/azgenerator/azgenerator.ts @@ -9,9 +9,10 @@ export async function processRequest(host: Host) { const debug = await host.GetValue('debug') || false; //host.Message({Channel:Channel.Warning, Text:"in azgenerator processRequest"}); try { + const cliCoreLib = await host.GetValue('cli-core-lib') || 'azure.cli.core'; const session = await startSession(host, {}, codeModelSchema); let model = new CodeModelCliImpl(session); - let files: any = await GenerateAll(model, true, debug); + let files: any = await GenerateAll(model, true, debug, cliCoreLib); if (model.SelectFirstExtension()) { do { let path = "azext_" + model.Extension_Name.replace("-", "_") + "/";