Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 36fd852

Browse files
authoredJan 19, 2023
Add feautre to generate ux metadata file (#1076)
* commit * Update template * Update template * Update template * Update template * Update template * update * Update the logic of getting module name and description of cmdlet
1 parent 7488842 commit 36fd852

File tree

12 files changed

+644
-68
lines changed

12 files changed

+644
-68
lines changed
 

‎.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,5 @@ package-deps.json
381381
/tests/**/license.txt
382382

383383
!/tests/**/test/*
384+
385+
.vscode/

‎docs/default-directory-layout.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ By default, AutoRest's PowerShell Generator will place all the generated files u
1313
- [/obj](#obj)
1414
- [/resources](#resources)
1515
- [/test](#test)
16+
- [/UX](#ux)
1617
- [/node-modules](#node-modules) (coming soon)
1718
- [.gitignore](#gitignore)
1819
- [\<format-file>.format.ps1xml](#format-fileformatps1xml)
@@ -62,6 +63,9 @@ Contains files not consumed by *any* process. Only for the repo as reference ass
6263
### /test
6364
Contains tests for the cmdlets. By default, it contains an example pester test and a httpipelinemock.ps1 script.
6465

66+
### /UX
67+
Contains metadata files for portal UX. Portal use these to display the usage of cmdlet for the resource in portal page.
68+
6569
### /node_modules
6670
Contains the packages from which the projects depend on.
6771

‎docs/repository-layout.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ In this repository
1313
- `powershell` - all the source code for the AutoRest.PowerShell extension.
1414
- `samples/` - a couple small non-azure examples to generate modules
1515
- `tests/` - **WORK IN PROGRESS** scripts to generate some tests to validate the code generator.
16+
- `UX/` - the portal UX metadata files use to display usage of powershell cmdlet for resource in portal page.
1617

1718
### The `powershell` plugin
1819
- `cmdlets/` - code for creating the cmdlet classes

‎powershell/autorest-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ docs-folder: $(current-folder)/docs
7575
dependency-module-folder: $(module-folder)/modules
7676
examples-folder: $(current-folder)/examples
7777
resources-folder: $(current-folder)/resources
78+
ux-folder: $(current-folder)/UX
7879
```
7980
8081
> File Paths

‎powershell/cmdlets/class.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
let ejs = require('ejs')
6+
const ejs = require('ejs');
77
import { Schema as NewSchema, SchemaType, ArraySchema, SchemaResponse, HttpParameter, ObjectSchema, BinaryResponse, DictionarySchema, ChoiceSchema, SealedChoiceSchema } from '@azure-tools/codemodel';
88
import { command, getAllProperties, JsonType, http, getAllPublicVirtualProperties, getVirtualPropertyFromPropertyName, ParameterLocation, getAllVirtualProperties, VirtualParameter, VirtualProperty } from '@azure-tools/codemodel-v3';
99
import { CommandOperation, OperationType, VirtualParameter as NewVirtualParameter } from '../utils/command-operation';
@@ -15,7 +15,7 @@ import {
1515
Switch, System, TerminalCase, toExpression, Try, Using, valueOf, Field, IsNull, Or, ExpressionOrLiteral, TerminalDefaultCase, xmlize, TypeDeclaration, And, IsNotNull, PartialMethod, Case, While
1616
} from '@azure-tools/codegen-csharp';
1717
import { ClientRuntime, EventListener, Schema, ArrayOf, EnumImplementation } from '../llcsharp/exports';
18-
import { Alias, ArgumentCompleterAttribute, AsyncCommandRuntime, AsyncJob, CmdletAttribute, ErrorCategory, ErrorRecord, Events, InvocationInfo, OutputTypeAttribute, ParameterAttribute, PSCmdlet, PSCredential, SwitchParameter, ValidateNotNull, verbEnum, GeneratedAttribute, DescriptionAttribute, ExternalDocsAttribute, CategoryAttribute, ParameterCategory, ProfileAttribute, PSObject, InternalExportAttribute, ExportAsAttribute, DefaultRunspace, RunspaceFactory, AllowEmptyCollectionAttribute, DoNotExportAttribute } from '../internal/powershell-declarations';
18+
import { Alias, ArgumentCompleterAttribute, AsyncCommandRuntime, AsyncJob, CmdletAttribute, ErrorCategory, ErrorRecord, Events, InvocationInfo, OutputTypeAttribute, ParameterAttribute, PSCmdlet, PSCredential, SwitchParameter, ValidateNotNull, verbEnum, GeneratedAttribute, DescriptionAttribute, ExternalDocsAttribute, CategoryAttribute, ParameterCategory, ProfileAttribute, PSObject, InternalExportAttribute, ExportAsAttribute, DefaultRunspace, RunspaceFactory, AllowEmptyCollectionAttribute, DoNotExportAttribute, HttpPathAttribute } from '../internal/powershell-declarations';
1919
import { State } from '../internal/state';
2020
import { Channel } from '@azure-tools/autorest-extension-base';
2121
import { IParameter } from '@azure-tools/codemodel-v3/dist/code-model/components';
@@ -1243,8 +1243,8 @@ export class CmdletClass extends Class {
12431243
yield Return();
12441244
}),
12451245
TerminalCase(Events.Progress.value, function* () {
1246-
yield 'var data = messageData();'
1247-
yield 'int progress = (int)data.Value;'
1246+
yield 'var data = messageData();';
1247+
yield 'int progress = (int)data.Value;';
12481248
yield 'string activityMessage, statusDescription;';
12491249
yield 'global::System.Management.Automation.ProgressRecordType recordType;';
12501250

@@ -1262,10 +1262,10 @@ export class CmdletClass extends Class {
12621262
yield '}';
12631263

12641264
// hardcode id = 1 because there is no need for nested progress bar
1265-
yield `WriteProgress(new global::System.Management.Automation.ProgressRecord(1, activityMessage, statusDescription)`;
1265+
yield 'WriteProgress(new global::System.Management.Automation.ProgressRecord(1, activityMessage, statusDescription)';
12661266
yield '{';
12671267
yield ' PercentComplete = progress,';
1268-
yield 'RecordType = recordType'
1268+
yield 'RecordType = recordType';
12691269
yield '});';
12701270
yield Return();
12711271
}),
@@ -1288,15 +1288,15 @@ export class CmdletClass extends Class {
12881288
yield ' return;';
12891289
yield '}';
12901290
});
1291-
yield Else(function * () {
1291+
yield Else(function* () {
12921292
yield 'if (data.ResponseMessage is System.Net.Http.HttpResponseMessage response)';
12931293
yield '{';
12941294
yield ' int delay = (int)(response.Headers.RetryAfter?.Delta?.TotalSeconds ?? 30);';
12951295
yield ' WriteDebug($"Delaying {delay} seconds before polling.");';
12961296
yield ' for (var now = 0; now < delay; ++now)';
12971297
yield ' {';
12981298
// hardcode id = 1 because there is no need for nested progress bar
1299-
yield ` WriteProgress(new global::System.Management.Automation.ProgressRecord(1, "In progress", "Checking operation status")`;
1299+
yield ' WriteProgress(new global::System.Management.Automation.ProgressRecord(1, "In progress", "Checking operation status")';
13001300
yield ' {';
13011301
yield ' PercentComplete = now * 100 / delay';
13021302
yield ' });';
@@ -1831,8 +1831,8 @@ export class CmdletClass extends Class {
18311831
// If defines externalDocs for operation
18321832
if (operation.details.default.externalDocs) {
18331833
this.add(new Attribute(ExternalDocsAttribute, {
1834-
parameters: [`${new StringExpression(this.operation.details.default.externalDocs?.url ?? "")}`,
1835-
`${new StringExpression(this.operation.details.default.externalDocs?.description ?? "")}`]
1834+
parameters: [`${new StringExpression(this.operation.details.default.externalDocs?.url ?? '')}`,
1835+
`${new StringExpression(this.operation.details.default.externalDocs?.description ?? '')}`]
18361836
}));
18371837
}
18381838

@@ -1846,6 +1846,16 @@ export class CmdletClass extends Class {
18461846

18471847
this.add(new Attribute(ProfileAttribute, { parameters: [...profileNames] }));
18481848
}
1849+
1850+
this.operation.callGraph.forEach((operationInfo) => {
1851+
let apiVersion = 'null';
1852+
if (operationInfo.apiVersions) {
1853+
apiVersion = operationInfo.apiVersions[0].version;
1854+
}
1855+
operationInfo.requests?.forEach((request) => {
1856+
this.add(new Attribute(HttpPathAttribute, { parameters: [`Path = "${request.protocol?.http?.path}"`, `ApiVersion = "${apiVersion}"`] }));
1857+
});
1858+
});
18491859
}
18501860
}
18511861

‎powershell/internal/powershell-declarations.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const ProfileAttribute: TypeDeclaration = new ClassType(rest, 'Profile');
4848
export const CategoryAttribute: TypeDeclaration = new ClassType(rest, 'Category');
4949
export const ExportAsAttribute: TypeDeclaration = new ClassType(rest, 'ExportAs');
5050
export const ParameterCategory: TypeDeclaration = new ClassType(rest, 'ParameterCategory');
51+
export const HttpPathAttribute: TypeDeclaration = new ClassType(rest, 'HttpPath');
5152

5253
export function ErrorCategory(category: string): Expression {
5354
return new LiteralExpression(`${sma}.ErrorCategory.${category}`);

0 commit comments

Comments
 (0)
Please sign in to comment.