зеркало из https://github.com/Azure/autorest.az.git
codemodel integrate
This commit is contained in:
Родитель
5fa8f34f14
Коммит
d5b0911443
|
@ -5,6 +5,7 @@
|
|||
|
||||
export interface CodeModelAz
|
||||
{
|
||||
init(): any;
|
||||
SelectFirstExtension(): boolean;
|
||||
SelectNextExtension(): boolean;
|
||||
|
||||
|
|
|
@ -4,14 +4,47 @@
|
|||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
|
||||
import { CodeModel, codeModelSchema } from '@azure-tools/codemodel';
|
||||
import { serialize, deserialize } from "@azure-tools/codegen";
|
||||
import { Session, startSession, Host, Channel } from '@azure-tools/autorest-extension-base';
|
||||
|
||||
export class CodeModelCliImpl implements CodeModelAz
|
||||
{
|
||||
public constructor(/* add model here */)
|
||||
{
|
||||
codeModel: CodeModel;
|
||||
options: any;
|
||||
extensionName: string;
|
||||
operationGroups: Array<any>;
|
||||
currentOperationGroupIndex: number;
|
||||
currentOperationGroup: Array<any>;
|
||||
operations: Array<any>;
|
||||
currentOperation: string;
|
||||
currentOperationIndex: number;
|
||||
currentParameterIndex: number;
|
||||
parameters: Array<any>;
|
||||
currentParameters: Array<any>;
|
||||
|
||||
|
||||
async init() {
|
||||
this.options = await this.session.getValue('az');
|
||||
this.extensionName = await this.options['az-name'];
|
||||
this.operationGroups = this.codeModel.operationGroups;
|
||||
this.currentOperationGroupIndex = 0;
|
||||
this.currentOperationGroup = this.operationGroups[this.currentOperationGroupIndex];
|
||||
this.operations = this.operationGroups[this.currentOperationGroupIndex].operations;
|
||||
this.currentOperationIndex = 0;
|
||||
this.currentOperation = this.operations[this.currentOperationIndex];
|
||||
this.currentParameterIndex = 0;
|
||||
this.parameters = this.operations[this.currentOperationIndex].request.parameters;
|
||||
this.currentParameters = this.parameters[this.currentParameterIndex];
|
||||
|
||||
}
|
||||
|
||||
public constructor(protected session: Session<CodeModel>)
|
||||
{
|
||||
this.codeModel = session.model;
|
||||
}
|
||||
|
||||
|
||||
public SelectFirstExtension(): boolean
|
||||
{
|
||||
// support only one initially
|
||||
|
@ -25,17 +58,18 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Extension_Name()
|
||||
{
|
||||
return "my-extension";
|
||||
|
||||
return this.extensionName;
|
||||
}
|
||||
|
||||
public get Extension_NameUnderscored()
|
||||
{
|
||||
return "my_extension";
|
||||
return this.extensionName.replace(/-/g, '_');
|
||||
}
|
||||
|
||||
public get Extension_NameClass(): string
|
||||
{
|
||||
return "MyExtensionClassName";
|
||||
return this.codeModel.info.title.replace(/ManagementClient/g, '');
|
||||
}
|
||||
|
||||
public get Extension_TestScenario(): any
|
||||
|
@ -46,17 +80,32 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
public SelectFirstCommandGroup(): boolean
|
||||
{
|
||||
// just enumerate through command groups in code-model-v4
|
||||
return true;
|
||||
this.session.message({Channel:Channel.Warning, Text:"currentOperationGroupIndex: " + this.currentOperationGroupIndex});
|
||||
if(this.operationGroups.length > 0) {
|
||||
this.currentOperationGroupIndex = 0;
|
||||
return true;
|
||||
} else {
|
||||
this.currentOperationGroupIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SelectNextCommandGroup(): boolean
|
||||
{
|
||||
return false;
|
||||
if(this.currentOperationGroupIndex < this.operationGroups.length - 1) {
|
||||
this.currentOperationGroupIndex++;
|
||||
this.currentOperationIndex = -1;
|
||||
this.currentParameterIndex = -1;
|
||||
return true;
|
||||
} else {
|
||||
this.currentOperationGroupIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public get CommandGroup_Name(): string
|
||||
{
|
||||
return "my-extension something";
|
||||
return this.currentOperationGroup['$keys'];
|
||||
}
|
||||
|
||||
public get CommandGroup_Help(): string
|
||||
|
@ -67,12 +116,26 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
public SelectFirstCommand(): boolean
|
||||
{
|
||||
// just enumerate through commands in command group
|
||||
return true;
|
||||
if(this.operations.length > 0) {
|
||||
this.currentOperationIndex = 0;
|
||||
this.currentParameterIndex = -1;
|
||||
return true;
|
||||
} else {
|
||||
this.currentOperationIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SelectNextCommand(): boolean
|
||||
{
|
||||
return false;
|
||||
if(this.currentOperationIndex < this.currentOperation.length - 1) {
|
||||
this.currentOperationIndex++;
|
||||
this.currentParameterIndex = -1;
|
||||
return true;
|
||||
} else {
|
||||
this.currentOperationIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SelectCommand(name: string): boolean
|
||||
|
@ -82,17 +145,19 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Command_FunctionName()
|
||||
{
|
||||
return "create_my_extension_something";
|
||||
return this.Command_MethodName.toLowerCase + "_" + this.Command_Name.replace(/ /g, "_");
|
||||
}
|
||||
|
||||
public get Command_Name(): string
|
||||
{
|
||||
return "my-extension something create";
|
||||
this.session.message({Channel:Channel.Warning, Text:"currentOperationGroupIndex: " + this.currentOperationGroupIndex + " currentOperationIndex: " + this.currentOperationIndex});
|
||||
//+ " operationGroup: " + this.session.model.operationGroups[thi]
|
||||
return this.session.model.operationGroups[this.currentOperationGroupIndex].operations[this.currentOperationIndex].language['az'].command;
|
||||
}
|
||||
|
||||
public get Command_MethodName(): string
|
||||
{
|
||||
return "show";
|
||||
return this.session.model.operationGroups[this.currentOperationGroupIndex].operations[this.currentOperationIndex].language['az'].name;
|
||||
}
|
||||
|
||||
public SelectFirstExample(): boolean
|
||||
|
@ -124,12 +189,26 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public SelectFirstOption(): boolean
|
||||
{
|
||||
return true;
|
||||
if(this.parameters.length > 0) {
|
||||
this.currentParameterIndex = 0;
|
||||
return true;
|
||||
/*} else if(this.currentParameterIndex == 0){
|
||||
return true;*/
|
||||
} else {
|
||||
this.currentParameterIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SelectNextOption(): boolean
|
||||
{
|
||||
return false;
|
||||
if(this.currentParameterIndex < this.parameters.length - 1) {
|
||||
this.currentParameterIndex++;
|
||||
return true;
|
||||
} else {
|
||||
this.currentParameterIndex = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public HasSubOptions(): boolean
|
||||
|
@ -149,12 +228,12 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Option_Name(): string
|
||||
{
|
||||
return "my-option";
|
||||
return this.parameters[this.currentParameterIndex].language['az'].name;
|
||||
}
|
||||
|
||||
public get Option_NameUnderscored(): string
|
||||
{
|
||||
return "my_option";
|
||||
return this.parameters[this.currentParameterIndex].language['az'].name.replace(/-/g, "_");
|
||||
}
|
||||
|
||||
public get Option_NamePython(): string
|
||||
|
@ -164,12 +243,12 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Option_IsRequired(): boolean
|
||||
{
|
||||
return true;
|
||||
return this.parameters[this.currentParameterIndex].required;
|
||||
}
|
||||
|
||||
public get Option_Description(): string
|
||||
{
|
||||
return "My option doing to enable amazing feature";
|
||||
return this.parameters[this.currentParameterIndex].language['az'].description;
|
||||
}
|
||||
|
||||
public get Option_PathSdk(): string
|
||||
|
@ -184,17 +263,25 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Option_Type(): string
|
||||
{
|
||||
return "str";
|
||||
return typeof this.parameters[this.currentParameterIndex];
|
||||
}
|
||||
|
||||
public get Option_IsList(): boolean
|
||||
{
|
||||
return false;
|
||||
return this.parameters[this.currentParameterIndex] instanceof Array? true: null;
|
||||
}
|
||||
|
||||
public get Option_EnumValues(): string[]
|
||||
{
|
||||
return ["value1", "value2"];
|
||||
if(this.parameters[this.currentParameterIndex].type == "sealed-choice") {
|
||||
var enumArray = [];
|
||||
for(var item in this.parameters[this.currentParameterIndex].choices) {
|
||||
enumArray.push(item);
|
||||
}
|
||||
return enumArray;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public SelectFirstMethod(): boolean
|
||||
|
@ -219,7 +306,7 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public get Method_Name(): string
|
||||
{
|
||||
return "show";
|
||||
return this.operations[this.currentOperationIndex].language['az'].name;
|
||||
}
|
||||
|
||||
public get Method_BodyParameterName(): string
|
||||
|
@ -229,17 +316,27 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public SelectFirstMethodParameter(): boolean
|
||||
{
|
||||
return true
|
||||
if(this.parameters.length > 0) {
|
||||
this.currentParameterIndex = 0;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public SelectNextMethodParameter(): boolean
|
||||
{
|
||||
return false;
|
||||
if(this.parameters.length > this.currentParameterIndex + 1) {
|
||||
this.currentParameterIndex++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public get MethodParameter_Name(): string
|
||||
{
|
||||
return "param";
|
||||
return this.parameters[this.currentParameterIndex].language['az'].name;
|
||||
}
|
||||
|
||||
public get MethodParamerer_MapsTo(): string
|
||||
|
@ -264,12 +361,12 @@ export class CodeModelCliImpl implements CodeModelAz
|
|||
|
||||
public GetPythonNamespace(): string
|
||||
{
|
||||
return "azure.mgmt.whatever";
|
||||
return this.options['namespace'];
|
||||
}
|
||||
|
||||
public get PythonMgmtClient(): string
|
||||
{
|
||||
return "MyMgmtClient";
|
||||
return this.codeModel.info.title;
|
||||
}
|
||||
|
||||
public get PythonOperationsName(): string
|
||||
|
|
|
@ -18,12 +18,15 @@ import { GenerateAzureCliReadme } from "./TemplateAzureCliReadme"
|
|||
import { GenerateAzureCliSetupCfg } from "./TemplateAzureCliSetupCfg"
|
||||
import { GenerateAzureCliSetupPy } from "./TemplateAzureCliSetupPy"
|
||||
import { CodeModelAz } from "./CodeModelAz";
|
||||
import { Session, startSession, Host, Channel } from '@azure-tools/autorest-extension-base';
|
||||
|
||||
export function GenerateAll(model: CodeModelAz,
|
||||
generateReport: any): any
|
||||
{
|
||||
export async function GenerateAll(model: CodeModelAz,
|
||||
generateReport: any) {
|
||||
let files: any = {};
|
||||
|
||||
await model.init();
|
||||
|
||||
|
||||
if (model.SelectFirstExtension())
|
||||
{
|
||||
do
|
||||
|
|
|
@ -10,8 +10,13 @@ export async function processRequest(host: Host) {
|
|||
try {
|
||||
const session = await startSession<CodeModel>(host, {}, codeModelSchema);
|
||||
|
||||
let model = new CodeModelCliImpl();
|
||||
let files: any = GenerateAll(model, true);
|
||||
let model = new CodeModelCliImpl(session);
|
||||
//session.message({Channel:Channel.Warning, Text:"Model operationGroup is " + serialize(session.model.operationGroups)});
|
||||
let operationGroup = session.model.operationGroups[0];
|
||||
let operations = operationGroup.operations;
|
||||
let operation = operations[0];
|
||||
session.message({Channel:Channel.Warning, Text:"Operation Command: " + operation.language['az'].command});
|
||||
let files: any = await GenerateAll(model, true);
|
||||
|
||||
for (let f in files) {
|
||||
host.WriteFile(f, files[f].join('\r\n'));
|
||||
|
|
|
@ -60,7 +60,7 @@ export async function processRequest(host: Host) {
|
|||
const session = await startSession<CodeModel>(host, {}, codeModelSchema);
|
||||
const plugin = await new AzNamer(session);
|
||||
const result = await plugin.process();
|
||||
host.WriteFile('aznamer-temp-output', serialize(result));
|
||||
host.WriteFile('aznamer-temp-output.yaml', serialize(result));
|
||||
} catch (E) {
|
||||
if (debug) {
|
||||
console.error(`${__filename} - FAILURE ${JSON.stringify(E)} ${E.stack}`);
|
||||
|
|
|
@ -193,7 +193,7 @@ export async function processRequest(host: Host) {
|
|||
const session = await startSession<CodeModel>(host, {}, codeModelSchema);
|
||||
const plugin = await new Modifiers(session);
|
||||
const result = await plugin.process();
|
||||
host.WriteFile("modifiers-temp-output", serialize(result));
|
||||
host.WriteFile("modifiers-temp-output.yaml", serialize(result));
|
||||
} catch (E) {
|
||||
if (debug) {
|
||||
console.error(`${__filename} - FAILURE ${JSON.stringify(E)} ${E.stack}`);
|
||||
|
|
Загрузка…
Ссылка в новой задаче