-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Core] az --version: Show command instruction and detailed instruction link when updates available #12981
[Core] az --version: Show command instruction and detailed instruction link when updates available #12981
Changes from all commits
2447912
4bdf5b4
fa9fed4
2b30229
e88a442
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# -------------------------------------------------------------------------------------------- | ||
# pylint: disable=line-too-long | ||
|
||
from __future__ import print_function | ||
|
||
__version__ = "2.3.1" | ||
|
@@ -29,6 +31,16 @@ | |
'content_version', 'kwargs', 'client', 'no_wait'] | ||
EVENT_FAILED_EXTENSION_LOAD = 'MainLoader.OnFailedExtensionLoad' | ||
|
||
_PACKAGE_UPGRADE_INSTRUCTIONS = {"YUM": ("sudo yum update -y azure-cli", "https://aka.ms/doc/UpdateAzureCliYum"), | ||
"ZYPPER": ("sudo zypper refresh && sudo zypper update -y azure-cli", "https://aka.ms/doc/UpdateAzureCliZypper"), | ||
"DEB": ("sudo apt-get update && sudo apt-get install --only-upgrade -y azure-cli", "https://aka.ms/doc/UpdateAzureCliApt"), | ||
"HOMEBREW": ("brew update && brew upgrade azure-cli", "https://aka.ms/doc/UpdateAzureCliHomebrew"), | ||
"PIP": ("curl -L https://aka.ms/InstallAzureCli | bash", "https://aka.ms/doc/UpdateAzureCliLinux"), | ||
"MSI": ("https://aka.ms/installazurecliwindows", "https://aka.ms/doc/UpdateAzureCliMsi"), | ||
"DOCKER": ("docker pull mcr.microsoft.com/azure-cli", "https://aka.ms/doc/UpdateAzureCliDocker")} | ||
|
||
_GENERAL_UPGRADE_INSTRUCTION = 'Instructions can be found at https://aka.ms/doc/InstallAzureCli' | ||
|
||
|
||
class AzCli(CLI): | ||
|
||
|
@@ -96,9 +108,36 @@ def show_version(self): | |
if updates_available == -1: | ||
logger.warning('Unable to check if your CLI is up-to-date. Check your internet connection.') | ||
elif updates_available: | ||
logger.warning('You have %i updates available. Consider updating your CLI installation. ' | ||
'Instructions can be found at https://docs.microsoft.com/en-us/cli/azure/install-azure-cli', | ||
updates_available) | ||
warning_msg = 'You have %i updates available. Consider updating your CLI installation' | ||
from azure.cli.core._environment import _ENV_AZ_INSTALLER | ||
installer = os.getenv(_ENV_AZ_INSTALLER) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we really need to print different messages based on platform? what about show all upgrade instructions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current link shown is doing something similiar, it puts all the links to each package in one page. But we got complains about it's not being useful, some users may not know their operating system or packaging well, they have difficulties to find the right instruction. |
||
instruction_msg = '' | ||
if installer in _PACKAGE_UPGRADE_INSTRUCTIONS: | ||
if installer == 'RPM': | ||
from azure.cli.core.util import get_linux_distro | ||
distname, _ = get_linux_distro() | ||
if not distname: | ||
instruction_msg = '. {}'.format(_GENERAL_UPGRADE_INSTRUCTION) | ||
else: | ||
distname = distname.lower().strip() | ||
if any(x in distname for x in ['centos', 'rhel', 'red hat', 'fedora']): | ||
installer = 'YUM' | ||
elif any(x in distname for x in ['opensuse', 'suse', 'sles']): | ||
installer = 'ZYPPER' | ||
else: | ||
instruction_msg = '. {}'.format(_GENERAL_UPGRADE_INSTRUCTION) | ||
elif installer == 'PIP': | ||
import platform | ||
system = platform.system() | ||
alternative_command = " or '{}' if you used our script for installation. Detailed instructions can be found at {}".format(_PACKAGE_UPGRADE_INSTRUCTIONS[installer][0], _PACKAGE_UPGRADE_INSTRUCTIONS[installer][1]) if system != 'Windows' else '' | ||
instruction_msg = " with 'pip install --upgrade azure-cli'{}".format(alternative_command) | ||
if instruction_msg: | ||
warning_msg += instruction_msg | ||
else: | ||
warning_msg += " with '{}'. Detailed instructions can be found at {}".format(_PACKAGE_UPGRADE_INSTRUCTIONS[installer][0], _PACKAGE_UPGRADE_INSTRUCTIONS[installer][1]) | ||
else: | ||
warning_msg += '. {}'.format(_GENERAL_UPGRADE_INSTRUCTION) | ||
logger.warning(warning_msg, updates_available) | ||
else: | ||
print('Your CLI is up-to-date.') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,9 +200,6 @@ def _get_version_string(name, version_dict): | |
_print() | ||
_print('Legal docs and information: aka.ms/AzureCliLegal') | ||
_print() | ||
if sys.version.startswith('2.7'): | ||
_print("* DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. \nA future version of Azure CLI will drop support for Python 2.7.") | ||
_print() | ||
version_string = output.getvalue() | ||
|
||
# if unable to query PyPI, use sentinel value to flag that | ||
|
@@ -805,8 +802,8 @@ def get_az_user_agent(): | |
|
||
agents = ["AZURECLI/{}".format(core_version)] | ||
|
||
_ENV_AZ_INSTALLER = 'AZ_INSTALLER' | ||
import os | ||
from azure.cli.core._environment import _ENV_AZ_INSTALLER | ||
if _ENV_AZ_INSTALLER in os.environ: | ||
agents.append('({})'.format(os.environ[_ENV_AZ_INSTALLER])) | ||
|
||
|
@@ -828,3 +825,22 @@ def user_confirmation(message, yes=False): | |
except NoTTYException: | ||
raise CLIError( | ||
'Unable to prompt for confirmation as no tty available. Use --yes.') | ||
|
||
|
||
def get_linux_distro(): | ||
if platform.system() != 'Linux': | ||
return None, None | ||
|
||
try: | ||
with open('/etc/os-release') as lines: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy and paste a sample for other reviewers:
|
||
tokens = [line.strip() for line in lines] | ||
except Exception: # pylint: disable=broad-except | ||
return None, None | ||
|
||
release_info = {} | ||
for token in tokens: | ||
if '=' in token: | ||
k, v = token.split('=', 1) | ||
release_info[k.lower()] = v.strip('"') | ||
|
||
return release_info.get('name', None), release_info.get('version_id', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just confirm, those short urls are all maintained actively
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of them are active now.