Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaozha committed May 20, 2020
2 parents 8bac461 + 15eda17 commit 608625b
Show file tree
Hide file tree
Showing 81 changed files with 18,598 additions and 867 deletions.
1 change: 1 addition & 0 deletions readme.az.common.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# configuration for az common

``` yaml $(az)
extension-mode: experimental

cli:
naming:
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export interface CodeModelAz
Extension_TestScenario: any;
Extension_ClientSubscriptionBound: boolean;
Extension_ClientBaseUrlBound: boolean;
Extension_Mode: string;

SelectFirstCommandGroup(): boolean;
SelectNextCommandGroup(): boolean;
Expand All @@ -73,6 +74,7 @@ export interface CodeModelAz
CommandGroup_Name: string;
CommandGroup_Help: string;
CommandGroup_DefaultName: string;
CommandGroup_HasShowCommand: boolean;

SelectFirstCommand(): boolean;
SelectNextCommand(): boolean;
Expand Down
38 changes: 34 additions & 4 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ export class CodeModelCliImpl implements CodeModelAz {
if (this.SelectFirstMethod()) {
let id_groups = new Map<string, string>();
id_groups = parseResourceId(this.Request.protocol.http.path);

let hasName = false;
if (this.SelectFirstMethodParameter()) {
do {
let parameters = this.MethodParameter;
let defaultName = parameters.language['cli']['cliKey'];
let defaultToMatch = '{' + defaultName + '}';

if(!isNullOrUndefined(id_groups)) {
for(let k of id_groups.entries()) {
if(k[1] == defaultToMatch && defaultName != 'resourceGroupName') {
Expand All @@ -178,20 +177,43 @@ export class CodeModelCliImpl implements CodeModelAz {
} else {
this.MethodParameter['RequiredByMethod'] = paramRequired.get(this.MethodParameter_Name) == paramTime ? true : false;
}
if (this.MethodParameter_MapsTo == 'name') {
hasName = true;
}
} while (this.SelectNextMethodParameter());
if (hasName) {
this.Method['hasName'] = true;
}
}
while (this.SelectNextMethod()) {
let id_groups = new Map<string, string>();
id_groups = parseResourceId(this.Request.protocol.http.path);
let hasName = false;
if (this.SelectFirstMethodParameter()) {
do {
let parameters = this.MethodParameter;
let defaultName = parameters.language['cli']['cliKey'];
let defaultToMatch = '{' + defaultName + '}';
if(!isNullOrUndefined(id_groups)) {
for(let k of id_groups.entries()) {
if(k[1] == defaultToMatch && defaultName != 'resourceGroupName') {
this.MethodParameter.language['az']['id_part'] = k[0];
}
}
}
if (parameters.language['cli'].required) {
this.MethodParameter['RequiredByMethod'] = true;
} else {
this.MethodParameter['RequiredByMethod'] = paramRequired.get(this.MethodParameter_Name) == paramTime ? true : false;
}
if (this.MethodParameter_MapsTo == 'name') {
hasName = true;
}
} while (this.SelectNextMethodParameter());
if (hasName) {
this.Method['hasName'] = true;
}
}

}
}
} while (this.SelectNextCommand());
Expand Down Expand Up @@ -403,7 +425,11 @@ export class CodeModelCliImpl implements CodeModelAz {
public get Extension_Name() {
return this.extensionName;
}


public get Extension_Mode() {
return this.codeModel.info['extensionMode'];
}

public get Extension_NameUnderscored() {
return this.extensionName.replace(/-/g, '_');
}
Expand Down Expand Up @@ -488,6 +514,10 @@ export class CodeModelCliImpl implements CodeModelAz {
return this.CommandGroup.$key || this.CommandGroup_Name;
}

public get CommandGroup_HasShowCommand(): boolean {
return this.CommandGroup.language['az']['hasShowCommand'];
}

public get CommandGroup_DefaultName(): string {
let eps = new EnglishPluralizationService();
return eps.singularize(this.CommandGroup.language['cli'].cliKey);
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/azgenerator/TemplateAzureCliAzextMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ export function GenerateAzureCliAzextMetadata(model: CodeModelAz) : string[] {
var output: string[] = [];

output.push('{');
output.push(' "azext.isExperimental": true,');
if(model.Extension_Mode == 'experimental') {
output.push(' "azext.isExperimental": true,');
} else if(model.Extension_Mode == 'preview') {
output.push(' "azext.isPreview": true,');
}

output.push(' "azext.minCliCoreVersion": "2.3.1"');
output.push('}');

Expand Down
12 changes: 8 additions & 4 deletions src/plugins/azgenerator/TemplateAzureCliCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ToMultiLine } from "../../utils/helper"
import { isNullOrUndefined } from "util";
import { SchemaType } from "@azure-tools/codemodel";

let showCommandFunctionName = undefined;
export function GenerateAzureCliCommands(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();

Expand Down Expand Up @@ -37,13 +38,15 @@ export function GenerateAzureCliCommands(model: CodeModelAz): string[] {
output.push(" client_factory=" + cf_name + ")");
let groupinfos = model.CommandGroup_Name.split(' ');
let extraInfo = "";
if(groupinfos.length == 2) {
if(groupinfos.length == 2 && model.Extension_Mode == 'experimental') {
extraInfo = ", is_experimental=True";
} else if(groupinfos.length == 2 && model.Extension_Mode == 'preview') {
extraInfo = ", is_preview=True";
}
ToMultiLine(" with self.command_group('" + model.CommandGroup_Name + "', " + model.Extension_NameUnderscored + "_" + model.GetModuleOperationName() + ", client_factory=" + cf_name + extraInfo + ") as g:", output);
let needWait = false;
do {
if (model.Command_IsLongRun) {
if (model.Command_IsLongRun && model.CommandGroup_HasShowCommand) {
needWait = true;
}
output = output.concat(getCommandBody(model));
Expand All @@ -53,7 +56,7 @@ export function GenerateAzureCliCommands(model: CodeModelAz): string[] {
}
while (model.SelectNextCommand());
if (needWait) {
output.push(" g.wait_command('wait')");
output.push(" g.custom_wait_command('wait', '" + showCommandFunctionName + "')");
}
}
} while (model.SelectNextCommandGroup());
Expand All @@ -76,7 +79,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false) {
let functionName = model.Command_FunctionName;
let methodName = model.Command_MethodName;
let endStr = ")";
if (model.Command_IsLongRun) {
if (model.Command_IsLongRun && model.CommandGroup_HasShowCommand) {
endStr = ", supports_no_wait=True" + endStr;
}
if (methodName != "show") {
Expand Down Expand Up @@ -113,6 +116,7 @@ function getCommandBody(model: CodeModelAz, needUpdate: boolean = false) {
}
}
else {
showCommandFunctionName = functionName;
ToMultiLine(" g.custom_show_command('" + methodName + "', '" + functionName + "'" + endStr, output);
}
return output;
Expand Down
73 changes: 56 additions & 17 deletions src/plugins/azgenerator/TemplateAzureCliCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function GenerateAzureCliCustom(model: CodeModelAz): string[] {
header.addFromImport("knack.util", ["CLIError"]);
}

if(required['nowait']) {
header.addFromImport("azure.cli.core.util", ["sdk_no_wait"]);
}

let output = [];
output = output.concat(body);
output.push("");
Expand Down Expand Up @@ -60,9 +64,9 @@ function GenerateBody(model: CodeModelAz, required: any): string[] {
needGeneric = true;
}
let needUpdate = model.Command_CanSplit;
output = output.concat(GetCommandBody(model, required, false, originalOperation, false));
output = output.concat(GetCommandBody(model, required, false, originalOperation, false, genericParameter));
if (needUpdate) {
output = output.concat(GetCommandBody(model, required, needUpdate, originalOperation, needGeneric));
output = output.concat(GetCommandBody(model, required, needUpdate, originalOperation, needGeneric, genericParameter));
}
}
while (model.SelectNextCommand());
Expand Down Expand Up @@ -153,7 +157,7 @@ function ConstructValuation(isGeneric: boolean, prefix: string, classNames: stri

}

function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, needUpdate: boolean = false, needGeneric: boolean = false) {
function GetSingleCommandDef(model: CodeModelAz, required: any, originalOperation: Operation, needUpdate: boolean = false, needGeneric: boolean = false, genericParameter: Parameter = null) {

let output: string[] = [];
let updatedMethodName: string = model.Command_FunctionName;
Expand All @@ -170,9 +174,13 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
output.push(call);

let allParam: Map<string, boolean> = new Map<string, boolean>();
let hasLongRun = false;
if (model.SelectFirstMethod()) {
do {

if(model.Method_IsLongRun && model.CommandGroup_HasShowCommand) {
required['nowait'] = true,
hasLongRun = true;
}
if (model.SelectFirstMethodParameter()) {
do {
if (model.MethodParameter_IsFlattened) {
Expand All @@ -182,6 +190,9 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
continue;
}

if(needUpdate && !isNullOrUndefined(genericParameter) && model.MethodParameter_MapsTo == model.Parameter_MapsTo(genericParameter)) {
continue;
}
if (model.MethodParameter_IsList && !model.MethodParameter_IsListOfSimple) {
if (model.Parameter_IsPolyOfSimple(model.MethodParameter)) {
continue;
Expand Down Expand Up @@ -215,6 +226,10 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
if (model.MethodParameter_Type == SchemaType.Constant) {
continue;
}

if(needUpdate && !isNullOrUndefined(genericParameter) && model.MethodParameter_MapsTo == model.Parameter_MapsTo(genericParameter)) {
continue;
}

if (model.MethodParameter_IsList && !model.MethodParameter_IsListOfSimple) {
if (model.Parameter_IsPolyOfSimple(model.MethodParameter)) {
Expand All @@ -239,23 +254,26 @@ function GetSingleCommandDef(model: CodeModelAz, originalOperation: Operation, n
} while (model.SelectNextMethod());
}

if(hasLongRun) {
output[output.length - 1] += ",";
output.push(indent + "no_wait=False");
}
output[output.length - 1] += "):";
return output;
}

function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: Operation = null, needGeneric: boolean = false) {
function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: Operation = null, needGeneric: boolean = false, genericParameter: Parameter = null, needUpdate: boolean = false) {
let originalParameters = null;
if (!isNullOrUndefined(originalOperation)) {
originalParameters = originalOperation.parameters;
if (!isNullOrUndefined(originalOperation.requests[0].parameters)) {
originalParameters = originalParameters.concat(originalOperation.requests[0].parameters);
}
}

let output: string[] = [];
let output_body: string[] = []
let output_method_call: string[] = [];

if (model.SelectFirstMethod()) {
// create body transformation for methods that support it
let methodName: string = model.Command_MethodName;
Expand All @@ -265,6 +283,9 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O
do {
if (model.SelectFirstMethodParameter()) {
do {
if(needUpdate && !isNullOrUndefined(genericParameter) && model.MethodParameter_MapsTo == model.Parameter_MapsTo(genericParameter)) {
continue;
}
if (model.MethodParameter_IsList && !model.MethodParameter_IsListOfSimple && !model.MethodParameter_IsSimpleArray) {
if (model.Parameter_IsPolyOfSimple(model.MethodParameter)) {
let baseParam = model.MethodParameter;
Expand Down Expand Up @@ -379,27 +400,36 @@ function GetSingleCommandBody(model: CodeModelAz, required, originalOperation: O
return output;
}

function GetCommandBody(model: CodeModelAz, required: boolean, needUpdate: boolean = false, originalOperation: Operation = null, needGeneric: boolean = false) {
function GetCommandBody(model: CodeModelAz, required: any, needUpdate: boolean = false, originalOperation: Operation = null, needGeneric: boolean = false, genericParameter: Parameter = null) {
// create, delete, list, show, update
let output: string[] = [];
output.push("");
output.push("");

output = output.concat(GetSingleCommandDef(model, originalOperation, needUpdate, needGeneric));
output = output.concat(GetSingleCommandBody(model, required, originalOperation, needGeneric))
output = output.concat(GetSingleCommandDef(model, required, originalOperation, needUpdate, needGeneric, genericParameter));
output = output.concat(GetSingleCommandBody(model, required, originalOperation, needGeneric, genericParameter, needUpdate))
return output;
}

function GetPolyMethodCall(model: CodeModelAz, prefix: any, originalOperation: Operation, originalParameters: Parameter[]): string[] {
let methodCall: string = prefix + "return ";
//methodCall += "client." + mode.GetModuleOperationName() +"." + ctx.Methods[methodIdx].Name + "(";
let indent = "";
let methodName = originalOperation.language['python'].name;
if (model.Method_IsLongRun) {
if (model.Method_IsLongRun && model.CommandGroup_HasShowCommand) {
methodName = "begin_" + methodName;
methodCall += "sdk_no_wait(";
indent = " ".repeat(methodCall.length);
methodCall += "no_wait," + "\n" + indent + "client." + methodName;

} else {
if(model.Method_IsLongRun) {
methodName = "begin_" + methodName;
}
methodCall += "client." + methodName + "(";
indent = " ".repeat(methodCall.length);
}
methodCall += "client." + methodName + "(";

let indent = " ".repeat(methodCall.length);

let cnt = 0;
for (let param of originalParameters) {
if (param.flattened) {
Expand Down Expand Up @@ -444,12 +474,21 @@ function GetMethodCall(model: CodeModelAz, prefix: any): string[] {
let methodCall: string = prefix + "return ";
//methodCall += "client." + mode.GetModuleOperationName() +"." + ctx.Methods[methodIdx].Name + "(";
let methodName = model.Method_Name;
if (model.Method_IsLongRun) {
let indent = "";
if (model.Method_IsLongRun && model.CommandGroup_HasShowCommand) {
methodName = "begin_" + methodName;
methodCall += "sdk_no_wait(";
indent = " ".repeat(methodCall.length);
methodCall += "no_wait," + "\n" + indent + "client." + methodName;
} else {
if(model.Method_IsLongRun) {
methodName = "begin_" + methodName;
}
methodCall += "client." + methodName + "(";
indent = " ".repeat(methodCall.length);
}
methodCall += "client." + methodName + "(";


let indent = " ".repeat(methodCall.length);
if (model.SelectFirstMethodParameter(true)) {
do {
let param = model.MethodParameter;
Expand Down
Loading

0 comments on commit 608625b

Please sign in to comment.