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

Commit

Permalink
Fix py style in action, init (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
LianwMS authored Jun 22, 2020
1 parent e6db3db commit 767d943
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 20 deletions.
36 changes: 20 additions & 16 deletions src/plugins/azgenerator/TemplateAzureCliActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,20 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { CodeModelAz } from "./CodeModelAz"
import { ToCamelCase, Capitalize, ToPythonString } from "../../utils/helper";
import { SchemaType, Parameter } from "@azure-tools/codemodel";
import { stringify } from "querystring";
import { HeaderGenerator } from "./Header";
import { Parameter, SchemaType } from "@azure-tools/codemodel";
import { isNullOrUndefined } from "util";
import { ToPythonString } from "../../utils/helper";
import { CodeModelAz } from "./CodeModelAz";
import { HeaderGenerator } from "./Header";


let allActions: Map<string, boolean> = new Map<string, boolean>();
export function GenerateAzureCliActions(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();

header.addImport("argparse");
header.addFromImport("knack.util", ["CLIError"]);
header.addFromImport("collections", ["defaultdict"]);
header.disableProtectedAccess = true;

let output: string[] = header.getLines();
let output: string[] = [];
let outputCode: string[] = [];

if (model.SelectFirstCommandGroup()) {
do {
Expand All @@ -38,19 +34,19 @@ export function GenerateAzureCliActions(model: CodeModelAz): string[] {
if (isNullOrUndefined(subActionName) || allActions.has(subActionName)) {
continue;
}
output = output.concat(GetAction(model, subActionName, model.MethodParameter, keyToMatch, valueToMatch))
outputCode = outputCode.concat(GetAction(model, subActionName, model.MethodParameter, keyToMatch, valueToMatch))
}
let actionName = model.Schema_ActionName(model.MethodParameter.schema);
if (isNullOrUndefined(actionName)) {
if (model.Parameter_IsPolyOfSimple(model.MethodParameter)) {
baseParam = model.MethodParameter;
}
}
}
else {
if (allActions.has(actionName)) {
continue;
}
output = output.concat(GetAction(model, actionName, model.MethodParameter))
outputCode = outputCode.concat(GetAction(model, actionName, model.MethodParameter))
}
} while (model.SelectNextMethodParameter());
}
Expand All @@ -61,6 +57,15 @@ export function GenerateAzureCliActions(model: CodeModelAz): string[] {
} while (model.SelectNextCommandGroup());
}

if (outputCode.length != 0) {
header.addImport("argparse");
header.addFromImport("knack.util", ["CLIError"]);
header.addFromImport("collections", ["defaultdict"]);
output = header.getLines().concat(outputCode);
}
else {
output = header.getLines();
}
output.push("");

return output;
Expand Down Expand Up @@ -98,8 +103,7 @@ function GetAction(model: CodeModelAz, actionName: string, param: Parameter, key
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter(true)) {
do {
if (model.Parameter_DefaultValue(model.SubMethodParameter) !== undefined)
{
if (model.Parameter_DefaultValue(model.SubMethodParameter) !== undefined) {
output.push(" d['" + model.Parameter_NamePython(model.SubMethodParameter) + "'] = " + ToPythonString(model.Parameter_DefaultValue(model.SubMethodParameter), model.Parameter_Type(model.SubMethodParameter)));
}
} while (model.SelectNextMethodParameter(true));
Expand Down Expand Up @@ -138,7 +142,7 @@ function GetAction(model: CodeModelAz, actionName: string, param: Parameter, key
}
model.ExitSubMethodParameters();
}

if (!foundProperties && preParamType == SchemaType.Dictionary) {
output.push(" d[k] = v");
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/azgenerator/TemplateAzureCliInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function GenerateAzureCliInit(model: CodeModelAz): string[] {

output.push("from azext_" + model.Extension_NameUnderscored + ".generated._help import helps # pylint: disable=unused-import");
output.push("try:");
output.push(" from azext_" + model.Extension_NameUnderscored + ".manual._help import helps");
output.push(" from azext_" + model.Extension_NameUnderscored + ".manual._help import helps # pylint: disable=reimported");
output.push("except ImportError:");
output.push(" pass");
output.push("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.cli.core import AzCommandsLoader
from azext_attestation.generated._help import helps # pylint: disable=unused-import
try:
from azext_attestation.manual._help import helps
from azext_attestation.manual._help import helps # pylint: disable=reimported
except ImportError:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.cli.core import AzCommandsLoader
from azext_datafactory.generated._help import helps # pylint: disable=unused-import
try:
from azext_datafactory.manual._help import helps
from azext_datafactory.manual._help import helps # pylint: disable=reimported
except ImportError:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from azure.cli.core import AzCommandsLoader
from azext_managed_network.generated._help import helps # pylint: disable=unused-import
try:
from azext_managed_network.manual._help import helps
from azext_managed_network.manual._help import helps # pylint: disable=reimported
except ImportError:
pass

Expand Down

0 comments on commit 767d943

Please sign in to comment.