Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/azure-cli-core/azure/cli/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ def _get_version_string(name, version_dict):
return version_string, updates_available


def get_az_version_json():
from azure.cli.core.extension import get_extensions
versions = {'extensions': {}}

for dist in get_installed_cli_distributions():
versions[dist.key] = dist.version
extensions = get_extensions()
if extensions:
for ext in extensions:
versions['extensions'][ext.name] = ext.version or 'Unknown'
return versions


def get_json_object(json_string):
""" Loads a JSON string as an object and converts all keys to snake case """

Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Release History
* Fix `vm create` failure in Azure Stack profile.
* vm monitor metrics tail/list-definitions: support query metric and list definitions for a vm.

**Misc.**

* Add preview command `az version show` to show the versions of Azure CLI modules and extensions in JSON format by default or format configured by --output

**Storage**

* `az storage account create`: Remove preview flag for --enable-hierarchical-namespace parameter
Expand Down
5 changes: 5 additions & 0 deletions src/azure-cli/azure/cli/command_modules/resource/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,8 @@
type: group
short-summary: Manage resource tags.
"""

helps['version'] = """
type: command
short-summary: Show the versions of Azure CLI modules and extensions in JSON format by default or format configured by --output
"""
Original file line number Diff line number Diff line change
Expand Up @@ -318,3 +318,6 @@ def load_command_table(self, _):

with self.command_group('') as g:
g.custom_command('rest', 'rest_call')

with self.command_group('') as g:
g.custom_command('version', 'show_version', is_preview=True)
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,12 @@ def rest_call(cmd, method, uri, headers=None, uri_parameters=None,
print(r.text)


def show_version(cmd):
from azure.cli.core.util import get_az_version_json
versions = get_az_version_json()
return versions


class _ResourceUtils(object): # pylint: disable=too-many-instance-attributes
def __init__(self, cli_ctx,
resource_group_name=None, resource_provider_namespace=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import unittest
from typing import Dict

from azure.cli.testsdk import ScenarioTest


class VersionTest(ScenarioTest):

def test_version(self):
output = self.cmd('az version').get_output_in_json()
self.assertIn('azure-cli', output)
self.assertIn('azure-cli-command-modules-nspkg', output)
self.assertIn('azure-cli-dev-tools', output)
self.assertIn('azure-cli-nspkg', output)
self.assertIn('azure-cli-telemetry', output)
self.assertIn('azure-cli-testsdk', output)
self.assertIn('extensions', output)
self.assertIsInstance(output['extensions'], Dict)


if __name__ == '__main__':
unittest.main()