Skip to content

Commit

Permalink
[Add Identity Script] Detect operation argument initialization statem…
Browse files Browse the repository at this point in the history
…ents (#15394)

* [Add Identity Script] Detect operation argument initialization statements

* fix identation
  • Loading branch information
deyaaeldeen authored May 27, 2021
1 parent 0e39419 commit 8564c84
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions common/tools/add-identity-mgmt-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ function updateREADME(mainModule, relativePath, namespace) {
"README file"
);

const [_, operation, operationArgs] = content.match(/client\.(.+?)\((.*)\).*$/ms);

const [_, operation, operationArgs] = content.match(/client\.(.+?)\((.*?)\).*$/ms);
const operationArgsInitializations = [...new Set(content.match(/(const (?!(client|authManager|subscriptionId)).*? = (?!require).*)/g))];
if ((operationArgs === "" && operationArgsInitializations.length > 0) || (operationArgs !== "" && operationArgsInitializations.length !== operationArgs.split(",").length)) {
throw new Error(`Bad README.md: The number of initializations does not match the number of arguments`);
}
const operationArgsInitializationsString = operationArgsInitializations.join("\n");
const operationHeader = operation
.split(".")
.reverse()
Expand Down Expand Up @@ -102,8 +106,7 @@ const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"];
// Please note that you can also use credentials from the \`@azure/ms-rest-nodeauth\` package instead.
const creds = new DefaultAzureCredential();
const client = new ${clientName}(creds, subscriptionId);
const resourceGroupName = "testresourceGroupName";
const resourceName = "testresourceName";
${operationArgsInitializationsString}
client.${operation}(${operationArgs}).then((result) => {
console.log("The result is:");
console.log(result);
Expand Down Expand Up @@ -140,9 +143,7 @@ In browser applications, we recommend using the \`InteractiveBrowserCredential\`
clientId: "<client id for your Azure AD app>",
tenantId: "<optional tenant for your organization>"
});
const client = new ${namespace}.${clientName}(creds, subscriptionId);
const resourceGroupName = "testresourceGroupName";
const resourceName = "testresourceName";
const client = new ${namespace}.${clientName}(creds, subscriptionId);${operationArgsInitializations.length === 0 ? "" : "\n" + operationArgsInitializations.map(str => " " + str).join("\n")}
client.${operation}(${operationArgs}).then((result) => {
console.log("The result is:");
console.log(result);
Expand Down

0 comments on commit 8564c84

Please sign in to comment.