Skip to content

Commit 800a45c

Browse files
authored
Merge pull request Azure#3798 from twitchax/preview_mapping
Create cmdlet-to-friendly mappings.
2 parents 0458675 + 5a1b297 commit 800a45c

File tree

4 files changed

+174
-1
lines changed

4 files changed

+174
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,4 @@ FakesAssemblies/
203203
/tools/*.dll
204204
*.GhostDoc.xml
205205
pingme.txt
206+
groupMapping*.json

build.proj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@
176176
<!-- Build all flavors of the Cmdlets -->
177177
<Target Name="Build" DependsOnTargets="RestoreNugetPackages;BuildMsBuildTask">
178178
<Message Importance="high" Text="Building Cmdlets..." />
179+
180+
<Exec ContinueOnError="false" Command="$(PowerShellCommand) -NonInteractive -NoLogo -NoProfile -Command &quot; . $(LibraryToolsFolder)\CreateMappings.ps1 -RootPath $(LibrarySourceFolder) -OutputFile $(PackageDirectory)\groupMapping.json -WarningFile $(PackageDirectory)\groupMappingWarnings.json -RulesFile $(LibraryToolsFolder)\CreateMappings_rules.json &quot;"/>
179181

180182
<MSBuild
181183
Projects="@(CmdletSolutionsToBuild)"
@@ -391,4 +393,4 @@
391393
<Message Importance="high" Text="Running live tests..." />
392394
<CallTarget Targets="LiveTests"/>
393395
</Target>
394-
</Project>
396+
</Project>

tools/CreateMappings.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Author: AaRoney.
2+
3+
# Define parameters.
4+
param(
5+
[string] $RootPath = "$PSScriptRoot\..\src",
6+
[string] $OutputFile = "groupMapping.json",
7+
[string] $WarningFile = "groupMappingWarnings.json",
8+
[string] $RulesFile = "CreateMappings_rules.json"
9+
);
10+
11+
# Load rules file from JSON.
12+
$rules = Get-Content -Raw -Path $RulesFile | ConvertFrom-Json;
13+
14+
# Initialize variables.
15+
$results = @{};
16+
$warnings = @();
17+
18+
# Find all cmdlet names by help file names in the repository.
19+
$cmdlets = Get-ChildItem $RootPath -Recurse | Where-Object { $_.FullName -cmatch ".*\\help\\.*-.*.md" };
20+
21+
$k = 0;
22+
$cmdlets | ForEach-Object {
23+
$cmdletPath = Split-Path $_.FullName -Parent;
24+
$cmdlet = $_.BaseName;
25+
26+
# First, match to module path.
27+
$matchedRule = @($rules | Where-Object { $cmdletPath -cmatch ".*$($_.Regex).*" })[0];
28+
29+
# Try to match this cmdlet with at least one rule.
30+
$possibleBetterMatch = @($rules | Where-Object { $cmdlet -cmatch ".*$($_.Regex).*" })[0];
31+
32+
# Look for a better match, but ensure that the groups match.
33+
if(($matchedRule.Group -ne $null) -and ($matchedRule.Group -eq $possibleBetterMatch.Group)) {
34+
$matchedRule = $possibleBetterMatch;
35+
}
36+
37+
# Take note of unmatched cmdlets and write to outputs.
38+
if($matchedRule -eq $null) {
39+
$warnings += $cmdlet;
40+
$results[$cmdlet] = "Other";
41+
} else {
42+
$results[$cmdlet] = $matchedRule.Alias;
43+
}
44+
45+
# Progress stuff.
46+
if($k % 100 -eq 0) {
47+
$percent = [math]::Floor($k / $cmdlets.Count * 100);
48+
Write-Progress -Activity "Processing cmdlets..." -Status "$($percent)%" -PercentComplete $percent;
49+
}
50+
$k++;
51+
};
52+
53+
# Write to files.
54+
$warnings | ConvertTo-Json | Out-File $WarningFile;
55+
$results | ConvertTo-Json | Out-File $OutputFile;
56+
57+
# Print conclusion.
58+
Write-Host ""
59+
Write-Host "$($results.Count) cmdlets successfully mapped: $($OutputFile)." -ForegroundColor Green;
60+
Write-Host "$($warnings.Count) cmdlets could not be mapped and were placed in 'Other': $($WarningFile)." -ForegroundColor Yellow;
61+
Write-Host ""

tools/CreateMappings_rules.json

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
[
2+
{ "regex": "ApiManagement", "alias": "API Management" },
3+
4+
{ "regex": "Snapshot", "group": "Virtual Machines", "alias": "VM Snapshots" },
5+
{ "regex": "Image", "group": "Virtual Machines", "alias": "VM Images" },
6+
{ "regex": "Vmss", "group": "Virtual Machines", "alias": "VM Scale Sets" },
7+
{ "regex": "Vhd", "group": "Virtual Machines", "alias": "VM VHDs" },
8+
{ "regex": "Disk", "group": "Virtual Machines", "alias": "VM Disks" },
9+
{ "regex": "ContainerService", "group": "Virtual Machines", "alias": "Container Service" },
10+
{ "regex": "VM.*Extension", "group": "Virtual Machines", "alias": "VM Extensions" },
11+
{ "regex": "Compute", "group": "Virtual Machines", "alias": "Virtual Machines" },
12+
{ "regex": "VM", "group": "Virtual Machines", "alias": "Virtual Machines" },
13+
14+
{ "regex": "ApplicationGateway", "group": "Network", "alias": "Application Gateway" },
15+
{ "regex": "ExpressRoute", "group": "Network", "alias": "ExpressRoute" },
16+
{ "regex": "LoadBalancer", "group": "Network", "alias": "Load Balancer" },
17+
{ "regex": "VirtualNetwork", "group": "Network", "alias": "Virtual Network" },
18+
{ "regex": "Vpn","group": "Network", "alias": "VPN" },
19+
{ "regex": "Route", "group": "Network", "alias": "Route" },
20+
{ "regex": "Dns", "group": "Network", "alias": "DNS" },
21+
{ "regex": "NetworkWatcher", "group": "Network", "alias": "Network Watcher" },
22+
{ "regex": "Network","group": "Network", "alias": "Networking" },
23+
24+
{ "regex": "AppService", "group": "App Service", "alias": "App Service" },
25+
{ "regex": "Websites", "group": "App Service", "alias": "App Service" },
26+
{ "regex": "WebApp", "group": "App Service", "alias": "App Service" },
27+
28+
{ "regex": "Storage", "alias": "Storage" },
29+
30+
{ "regex": "ServiceBus", "alias": "Service Bus" },
31+
32+
{ "regex": "Sql", "alias": "SQL" },
33+
34+
{ "regex": "ContainerService", "group": "Container Service", "alias": "Container Service" },
35+
{ "regex": "ACS", "group": "Container Service", "alias": "Container Service" },
36+
37+
{ "regex": "KeyVault", "alias": "Key Vault" },
38+
39+
{ "regex": "Iot", "alias": "IoT" },
40+
41+
{ "regex": "DataLake", "alias": "Data Lake" },
42+
43+
{ "regex": "Batch", "alias": "Batch" },
44+
45+
{ "regex": "AnalysisServices", "alias": "Analysis Services" },
46+
47+
{ "regex": "Automation", "alias": "Automation" },
48+
49+
{ "regex": "Recovery", "alias": "Recovery" },
50+
51+
{ "regex": "Backup", "alias": "Backup" },
52+
53+
{ "regex": "Cdn", "alias": "CDN" },
54+
55+
{ "regex": "CognitiveService", "alias": "Cognitive Services" },
56+
57+
{ "regex": "AvailabilitySet", "alias": "Availability Sets" },
58+
59+
{ "regex": "EventHub", "alias": "Event Hub" },
60+
61+
{ "regex": "HDInsight", "alias": "HD Insights" },
62+
63+
{ "regex": "LogicApp", "alias": "Logic Apps" },
64+
65+
{ "regex": "IntegrationAccount", "alias": "Integration Accounts" },
66+
67+
{ "regex": "NotificationHub", "alias": "Notification Hubs" },
68+
69+
{ "regex": "OperationalInsights", "alias": "Operational Insights" },
70+
71+
{ "regex": "PowerBI", "alias": "Power BI" },
72+
73+
{ "regex": "RedisCache", "alias": "Redis Cache" },
74+
75+
{ "regex": "Scheduler", "alias": "Scheduler" },
76+
77+
{ "regex": "SiteRecovery", "alias": "Site Recovery" },
78+
79+
{ "regex": "ServerManagement", "alias": "Server Management" },
80+
81+
{ "regex": "StreamAnalytics", "alias": "Stream Analytics" },
82+
83+
{ "regex": "TrafficManager", "alias": "Traffic Manager" },
84+
85+
{ "regex": "MachineLearning", "group": "Machine Learning", "alias": "Machine Learning" },
86+
{ "regex": "Ml", "group": "Machine Learning", "alias": "Machine Learning" },
87+
88+
{ "regex": "Billing", "alias": "Billing" },
89+
90+
{ "regex": "Insights", "alias": "Insights" },
91+
92+
{ "regex": "Dtl", "group": "DevTest Labs", "alias": "DevTest Labs" },
93+
{ "regex": "DevTestLabs", "group": "DevTest Labs", "alias": "DevTest Labs" },
94+
95+
{ "regex": "DataFactory", "group": "Data Factories", "alias": "Data Factories" },
96+
{ "regex": "DataFactories", "group": "Data Factories", "alias": "Data Factories" },
97+
98+
{ "regex": "Media", "alias": "Media Services" },
99+
100+
{ "regex": "UsageAggregates", "alias": "Usage Aggregates" },
101+
102+
{ "regex": "Tags", "alias": "Tags" },
103+
104+
{ "regex": "Profile", "alias": "Profile" },
105+
106+
{ "regex": "Policy", "group": "Resources", "alias": "Policies" },
107+
{ "regex": "AD", "group": "Resources", "alias": "Active Directory" },
108+
{ "regex": "Resource", "group": "Resources", "alias": "Resources" }
109+
]

0 commit comments

Comments
 (0)