Skip to content

Commit 53ce56b

Browse files
committed
format
1 parent dbb01fc commit 53ce56b

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/azure-cli-core/azure/cli/core/commands/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ class AzCliCommandInvoker(CommandInvoker):
507507
# pylint: disable=too-many-statements,too-many-locals,too-many-branches
508508
def execute(self, args):
509509
args_copy = args[:]
510-
511510
from knack.events import (EVENT_INVOKER_PRE_CMD_TBL_CREATE, EVENT_INVOKER_POST_CMD_TBL_CREATE,
512511
EVENT_INVOKER_CMD_TBL_LOADED, EVENT_INVOKER_PRE_PARSE_ARGS,
513512
EVENT_INVOKER_POST_PARSE_ARGS,
@@ -706,12 +705,12 @@ def _what_if(self, args):
706705
index = args.index('--subscription')
707706
if index + 1 < len(args):
708707
subscription_value = args[index + 1]
709-
subscription_id = subscription_value
708+
subscription_id = subscription_value
710709
else:
711710
from azure.cli.core.commands.client_factory import get_subscription_id
712711
subscription_id = get_subscription_id(self.cli_ctx)
713712
print(f"DEBUG: Using current login subscription ID: {subscription_id}")
714-
713+
715714
args = ["az"] + args if args[0] != 'az' else args
716715
command = " ".join(args)
717716
what_if_result = show_what_if(self.cli_ctx, command, subscription_id=subscription_id)
@@ -724,14 +723,17 @@ def _what_if(self, args):
724723
# Return the formatted what-if output as the result
725724
# Similar to the normal flow in execute() method
726725
return CommandResultItem(
727-
what_if_result,
726+
what_if_result,
728727
table_transformer=None,
729728
is_query_active=self.data.get('query_active', False),
730729
exit_code=0
731730
)
732-
except Exception as ex:
731+
except (CLIError, ValueError, KeyError) as ex:
733732
# If what-if service fails, still show an informative message
734-
return CommandResultItem(None, exit_code=1, error=CLIError(f'What-if preview failed: {str(ex)}\nNote: This was a preview operation. No actual changes were made.'))
733+
return CommandResultItem(None, exit_code=1,
734+
error=CLIError(f'What-if preview failed: {str(ex)}\n'
735+
f'Note: This was a preview operation. '
736+
f'No actual changes were made.'))
735737

736738
@staticmethod
737739
def _extract_parameter_names(args):

src/azure-cli-core/azure/cli/core/what_if.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def _create_resource_change(change_data):
166166

167167
return WhatIfOperationResult(changes, potential_changes, [])
168168

169+
169170
def show_what_if(cli_ctx, azcli_script: str, subscription_id: str = None, no_pretty_print=False):
170171
from azure.cli.core.commands.client_factory import get_subscription_id
171172
from azure.cli.command_modules.resource._formatters import format_what_if_operation_result

src/azure-cli/azure/cli/command_modules/sql/custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4369,7 +4369,7 @@ def server_create(
43694369
external_admin_principal_type=None,
43704370
external_admin_sid=None,
43714371
external_admin_name=None,
4372-
what_if=None,
4372+
what_if=None, # pylint: disable=unused-argument
43734373
**kwargs):
43744374
'''
43754375
Creates a server.

src/azure-cli/azure/cli/command_modules/util/tests/latest/test_whatif.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def setUp(self):
1818
self.test_script_path = os.path.join(TEST_DIR, 'test_whatif_script.sh')
1919

2020
@patch('azure.cli.core.commands.client_factory.get_subscription_id')
21-
@patch('azure.cli.core.what_if.get_auth_headers')
22-
@patch('azure.cli.core.what_if.make_what_if_request')
21+
@patch('azure.cli.core.what_if._get_auth_headers')
22+
@patch('azure.cli.core.what_if._make_what_if_request')
2323
def test_what_if_command(self, mock_make_request, mock_get_headers, mock_get_subscription_id):
2424
mock_get_subscription_id.return_value = 'test-subscription-id'
2525
mock_get_headers.return_value = {'Authorization': 'Bearer test-token'}

0 commit comments

Comments
 (0)