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
2 changes: 1 addition & 1 deletion src/containerapp-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Release History
upcoming
++++++
* containerapp-preview requires the version of containerapp extension >= 0.3.36

* containerapp-preview auto install containerapp extension if not exist

1.0.0b1
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from azure.cli.core import AzCommandsLoader

from azext_containerapp_preview._help import helps # pylint: disable=unused-import
from azext_containerapp_preview._utils import (_get_azext_containerapp_module)
from azext_containerapp_preview._utils import (_get_azext_containerapp_module, auto_install_containerapp_extension_if_not_exist)


class ContainerappPreviewCommandsLoader(AzCommandsLoader):
Expand All @@ -18,6 +18,7 @@ def __init__(self, cli_ctx=None):
client_factory=None)
super(ContainerappPreviewCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=containerapp_preview_custom)
auto_install_containerapp_extension_if_not_exist(self)

def load_command_table(self, args):
from azext_containerapp_preview.commands import load_command_table
Expand Down
24 changes: 23 additions & 1 deletion src/containerapp-preview/azext_containerapp_preview/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from azure.cli.core.azclierror import NoTTYError, ValidationError
from azure.cli.core.azclierror import ValidationError
from knack.util import CLIError
from knack.log import get_logger

Expand Down Expand Up @@ -38,6 +38,28 @@ def _get_azext_containerapp_module(module_name):
# Import the extension module
from importlib import import_module
azext_custom = import_module(module_name)

# need to reload preview's _help, because the containerapp's _help will overwrite the preview's _help after importing the containerapp module.
from azext_containerapp_preview import _help
from importlib import reload
reload(_help)

return azext_custom
except ImportError as ie:
raise CLIError(ie) from ie


def auto_install_containerapp_extension_if_not_exist(cmd):
from azure.cli.core.extension import extension_exists

if not extension_exists(GA_CONTAINERAPP_EXTENSION_NAME):
_install_containerapp_extension(cmd, GA_CONTAINERAPP_EXTENSION_NAME)


def _install_containerapp_extension(cmd, extension_name, upgrade=False):
try:
from azure.cli.core.extension import operations
operations.add_extension(cmd=cmd, extension_name=extension_name, upgrade=upgrade)
except Exception: # nopa pylint: disable=broad-except
return False
return True