diff --git a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py index 05ece5183bd..f22e700b6c4 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_bicep.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_bicep.py @@ -124,6 +124,16 @@ def ensure_bicep_installation(release_tag=None, stdout=True): raise ClientRequestError(f"Error while attempting to download Bicep CLI: {err}") +def remove_bicep_installation(): + system = platform.system() + installation_path = _get_bicep_installation_path(system) + + if os.path.exists(installation_path): + os.remove(installation_path) + if os.path.exists(_bicep_version_check_file_path): + os.remove(_bicep_version_check_file_path) + + def is_bicep_file(file_path): return file_path.lower().endswith(".bicep") diff --git a/src/azure-cli/azure/cli/command_modules/resource/_help.py b/src/azure-cli/azure/cli/command_modules/resource/_help.py index d0022f7c9bd..69f668d26e8 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/_help.py +++ b/src/azure-cli/azure/cli/command_modules/resource/_help.py @@ -2457,6 +2457,11 @@ text: az bicep install --version v0.2.212 """ +helps['bicep uninstall'] = """ +type: command +short-summary: Uninstall Bicep CLI. +""" + helps['bicep upgrade'] = """ type: command short-summary: Upgrade Bicep CLI to the latest version. diff --git a/src/azure-cli/azure/cli/command_modules/resource/commands.py b/src/azure-cli/azure/cli/command_modules/resource/commands.py index 0a5c4391d37..ed35ca1dba1 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/commands.py +++ b/src/azure-cli/azure/cli/command_modules/resource/commands.py @@ -455,6 +455,7 @@ def load_command_table(self, _): with self.command_group('bicep') as g: g.custom_command('install', 'install_bicep_cli') + g.custom_command('uninstall', 'uninstall_bicep_cli') g.custom_command('upgrade', 'upgrade_bicep_cli') g.custom_command('build', 'build_bicep_file') g.custom_command('decompile', 'decompile_bicep_file') diff --git a/src/azure-cli/azure/cli/command_modules/resource/custom.py b/src/azure-cli/azure/cli/command_modules/resource/custom.py index de27275fc1e..432c6400eb2 100644 --- a/src/azure-cli/azure/cli/command_modules/resource/custom.py +++ b/src/azure-cli/azure/cli/command_modules/resource/custom.py @@ -52,6 +52,7 @@ run_bicep_command, is_bicep_file, ensure_bicep_installation, + remove_bicep_installation, get_bicep_latest_release_tag, get_bicep_available_release_tags, validate_bicep_target_scope @@ -3413,6 +3414,10 @@ def install_bicep_cli(cmd, version=None): ensure_bicep_installation(release_tag=version) +def uninstall_bicep_cli(cmd): + remove_bicep_installation() + + def upgrade_bicep_cli(cmd): latest_release_tag = get_bicep_latest_release_tag() ensure_bicep_installation(release_tag=latest_release_tag) @@ -3426,6 +3431,8 @@ def build_bicep_file(cmd, file, stdout=None, outdir=None, outfile=None): args += ["--outfile", outfile] if stdout: args += ["--stdout"] + print(run_bicep_command(args)) + return run_bicep_command(args)