Co-authored-by: xichen <xichen@microsoft.com>
This commit is contained in:
xichen 2020-06-24 11:40:05 +08:00 коммит произвёл GitHub
Родитель 256f976810
Коммит fd191dd41d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 43 добавлений и 20 удалений

Просмотреть файл

@ -182,4 +182,7 @@ export interface CodeModelAz {
GatherInternalResource();
FindExampleWaitById(id: string): string[][];
RandomizeNames: boolean;
// readme config
CliCoreLib: string;
}

Просмотреть файл

@ -43,6 +43,10 @@ export class CodeModelCliImpl implements CodeModelAz {
private _clientBaseUrlBound: boolean;
private _clientAuthenticationPolicy: string;
private _cliCoreLib: string;
private static readonly DEFAULT_CLI_CORE_LIB = 'azure.cli.core';
async init() {
this.options = await this.session.getValue('az');
this.extensionName = this.options['extensions'];
@ -2214,4 +2218,15 @@ export class CodeModelCliImpl implements CodeModelAz {
});
return ret;
}
public set CliCoreLib(lib: string) {
this._cliCoreLib = lib;
}
public get CliCoreLib(): string {
if (isNullOrUndefined(this._cliCoreLib)) {
return CodeModelCliImpl.DEFAULT_CLI_CORE_LIB;
}
return this._cliCoreLib;
}
}

Просмотреть файл

@ -25,7 +25,7 @@ import { GenerateNamespaceInit } from "./TemplateAzureCliNamespaceInit"
import { GenerateAzureCliTestInit } from "./TemplateAzureCliTestInit"
export async function GenerateAll(model: CodeModelAz,
generateReport: any, debug: boolean, cliCoreLib: string) {
generateReport: any, debug: boolean) {
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, 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/_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/_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, cliCoreLib);
files[path + "__init__.py"] = GenerateAzureCliInit(model);
files[pathTop + "HISTORY.rst"] = GenerateAzureCliHistory(model);
files[pathTop + "README.md"] = GenerateAzureCliReadme(model);
files[pathTop + "setup.cfg"] = GenerateAzureCliSetupCfg(model);

Просмотреть файл

@ -7,14 +7,14 @@ import { CodeModelAz } from "./CodeModelAz"
import { HeaderGenerator } from "./Header";
import { isNullOrUndefined } from "util";
export function GenerateAzureCliClientFactory(model: CodeModelAz, cliCoreLib: string): string[] {
export function GenerateAzureCliClientFactory(model: CodeModelAz): 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 " + cliCoreLib + ".commands.client_factory import get_mgmt_service_client");
output.push(" from " + model.CliCoreLib + ".commands.client_factory import get_mgmt_service_client");
output.push(" from ..vendored_sdks." + model.PythonOperationsName + " import " + model.PythonMgmtClient);
if (!isNullOrUndefined(model.Extension_ClientAuthenticationPolicy)) {

Просмотреть файл

@ -10,13 +10,13 @@ import { isNullOrUndefined } from "util";
import { SchemaType } from "@azure-tools/codemodel";
let showCommandFunctionName = undefined;
export function GenerateAzureCliCommands(model: CodeModelAz, cliCoreLib: string): string[] {
export function GenerateAzureCliCommands(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
// this can't be currently reproduced
header.disableTooManyStatements = true;
header.disableTooManyLocals = true;
header.addFromImport(cliCoreLib + ".commands", ["CliCommandType"]);
header.addFromImport(model.CliCoreLib + ".commands", ["CliCommandType"]);
let output: string[] = []
output.push("");

Просмотреть файл

@ -9,7 +9,7 @@ import { Capitalize, ToCamelCase, ToMultiLine, ToPythonString } from '../../util
import { CodeModelAz } from "./CodeModelAz";
import { HeaderGenerator } from "./Header";
export function GenerateAzureCliCustom(model: CodeModelAz, cliCoreLib: string): string[] {
export function GenerateAzureCliCustom(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
header.disableTooManyLines = true;
@ -29,7 +29,7 @@ export function GenerateAzureCliCustom(model: CodeModelAz, cliCoreLib: string):
}
if(required['nowait']) {
header.addFromImport(cliCoreLib + ".util", ["sdk_no_wait"]);
header.addFromImport(model.CliCoreLib + ".util", ["sdk_no_wait"]);
}
if(required['disableUnusedArgument']) {

Просмотреть файл

@ -7,9 +7,9 @@ import { CodeModelAz } from "./CodeModelAz"
import { HeaderGenerator } from "./Header";
import { ToMultiLine } from "../../utils/helper"
export function GenerateAzureCliInit(model: CodeModelAz, cliCoreLib: string): string[] {
export function GenerateAzureCliInit(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
header.addFromImport(cliCoreLib, ["AzCommandsLoader"]);
header.addFromImport(model.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, cliCoreLib: string): st
output.push("class " + model.Extension_NameClass + "CommandsLoader(AzCommandsLoader):");
output.push("");
output.push(" def __init__(self, cli_ctx=None):");
output.push(" from " + cliCoreLib + ".commands import CliCommandType");
output.push(" from " + model.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#{}',");

Просмотреть файл

@ -20,7 +20,7 @@ let hasLocationValidator = false;
let hasTags = false;
let actions: string[] = [];
export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean, cliCoreLib: string): string[] {
export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean): string[] {
var output_args: string[] = [];
output_args.push("");
@ -65,7 +65,7 @@ export function GenerateAzureCliParams(model: CodeModelAz, debug: boolean, cliCo
if (hasResourceGroup) parameterImports.push("resource_group_name_type");
if (hasLocation) parameterImports.push("get_location_type");
header.addFromImport(cliCoreLib + ".commands.parameters", parameterImports);
header.addFromImport(model.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, cliCo
validatorImports.push("validate_file_or_dict");
}
if (validatorImports.length > 0) {
header.addFromImport(cliCoreLib + '.commands.validators', validatorImports);
header.addFromImport(model.CliCoreLib + '.commands.validators', validatorImports);
}
if (hasActions) {

Просмотреть файл

@ -3,16 +3,21 @@ import { CodeModel, codeModelSchema } from '@azure-tools/codemodel';
import { EOL } from "os";
import { CodeModelCliImpl } from "./CodeModelAzImpl";
import { GenerateAll } from "./Generator";
import { isNullOrUndefined } from 'util';
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<CodeModel>(host, {}, codeModelSchema);
let model = new CodeModelCliImpl(session);
let files: any = await GenerateAll(model, true, debug, cliCoreLib);
const cliCoreLib: string = await host.GetValue('cli-core-lib');
if (!isNullOrUndefined(cliCoreLib) && cliCoreLib.length > 0) {
model.CliCoreLib = cliCoreLib;
}
let files: any = await GenerateAll(model, true, debug);
if (model.SelectFirstExtension()) {
do {
let path = "azext_" + model.Extension_Name.replace("-", "_") + "/";