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

Commit

Permalink
Merge pull request #33 from microsoft/issue32
Browse files Browse the repository at this point in the history
[BUG--FIX] issue 32: setup command fails to get az cli version
  • Loading branch information
dennisseah authored Apr 30, 2020
2 parents 928b5ba + fc5ecdd commit eefedbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
5 changes: 1 addition & 4 deletions src/commands/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,7 @@ describe("test getAPIClients function", () => {

describe("test isAzCLIInstall function", () => {
it("positive test", async () => {
const version = JSON.stringify({
"azure-cli": "2.0.79",
});
jest.spyOn(shell, "exec").mockResolvedValueOnce(version);
jest.spyOn(shell, "exec").mockResolvedValueOnce("azure-cli 2.5.0");
await isAzCLIInstall();
});
it("negative test: version is not returned", async () => {
Expand Down
17 changes: 11 additions & 6 deletions src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ interface APIClients {

export const isAzCLIInstall = async (): Promise<void> => {
try {
const result = await exec("az", ["version"]);
try {
logger.info(`az cli vesion ${JSON.parse(result)["azure-cli"]}`);
} catch (e) {
const result = await exec("az", ["--version"]);
const ver = result
.split("\n")
.find((s) => s.startsWith("azure-cli "))
?.split(/\s+/);
const version = ver && ver.length === 2 ? ver[1] : null;

if (version) {
logger.info(`az cli vesion ${version}`);
} else {
throw buildError(
errorStatusCode.ENV_SETTING_ERR,
"setup-cmd-az-cli-get-version-err",
e
"setup-cmd-az-cli-parse-az-version-err"
);
}
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

"setup-cmd-failed": "Setup command was not successfully executed.",
"setup-cmd-az-cli-err": "az command line was not installed.",
"setup-cmd-az-cli-parse-az-version-err": "Could not determine az cli version, the installed azure cli might not be supported.",
"setup-cmd-prompt-err-no-subscriptions": "No subscriptions found.",
"setup-cmd-prompt-err-subscription-missing": "Subscription Identifier was missing.",
"setup-cmd-prompt-err-input-file-missing": "{0} did not exist or not accessible. Make sure that it is accessible.",
Expand Down

0 comments on commit eefedbf

Please sign in to comment.