diff --git a/.vscode/launch.json b/.vscode/launch.json index c2a47d74891..d5343a3af79 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,7 +3,7 @@ "configurations": [ { "name": "Azure CLI Debug (Integrated Console)", - "type": "python", + "type": "debugpy", "request": "launch", "python": "${command:python.interpreterPath}", "program": "${workspaceRoot}/src/azure-cli/azure/cli/__main__.py", @@ -12,16 +12,11 @@ "--help" ], "console": "integratedTerminal", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ], "justMyCode": false }, { "name": "Azure CLI Debug (External Console)", - "type": "python", + "type": "debugpy", "request": "launch", "stopOnEntry": true, "python": "${command:python.interpreterPath}", @@ -31,14 +26,10 @@ "--help" ], "console": "externalTerminal", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit" - ] }, { "name": "Azdev Scripts", - "type": "python", + "type": "debugpy", "request": "launch", "python": "${command:python.interpreterPath}", "program": "${workspaceRoot}/tools/automation/__main__.py", @@ -47,11 +38,6 @@ "--help" ], "console": "integratedTerminal", - "debugOptions": [ - "WaitOnAbnormalExit", - "WaitOnNormalExit", - "RedirectOutput" - ] } ] -} +} \ No newline at end of file diff --git a/src/azure-cli-core/azure/cli/core/__init__.py b/src/azure-cli-core/azure/cli/core/__init__.py index e44a72fc5f1..97052466f8f 100644 --- a/src/azure-cli-core/azure/cli/core/__init__.py +++ b/src/azure-cli-core/azure/cli/core/__init__.py @@ -597,7 +597,7 @@ def get(self, args): return None # Get the top-level command, like `network` in `network vnet create -h` - top_command = args[0] + top_command = args[0].lower() index = self.INDEX[self._COMMAND_INDEX] # Check the command index for (command: [module]) mapping, like # "network": ["azure.cli.command_modules.natgateway", "azure.cli.command_modules.network", "azext_firewall"] diff --git a/src/azure-cli-core/azure/cli/core/tests/test_command_registration.py b/src/azure-cli-core/azure/cli/core/tests/test_command_registration.py index 21d03d47b5e..7d5fa26afe2 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_command_registration.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_command_registration.py @@ -389,6 +389,42 @@ def update_and_check_index(): del INDEX[CommandIndex._COMMAND_INDEX_CLOUD_PROFILE] del INDEX[CommandIndex._COMMAND_INDEX] + def test_command_index_case_sensitivity(self): + """Test that CommandIndex.get() method is case-insensitive for command arguments.""" + from azure.cli.core._session import INDEX + from azure.cli.core import CommandIndex, __version__ + + cli = DummyCli() + command_index = CommandIndex(cli) + + # Set up a command index with lowercase entries + INDEX[CommandIndex._COMMAND_INDEX_VERSION] = __version__ + INDEX[CommandIndex._COMMAND_INDEX_CLOUD_PROFILE] = cli.cloud.profile + INDEX[CommandIndex._COMMAND_INDEX] = { + "hello": ["azure.cli.command_modules.hello"], + "account": ["azure.cli.command_modules.account"], + "version": ["azure.cli.command_modules.version"] + } + + # Test lowercase - should work + result_lower = command_index.get(["hello", "world"]) + self.assertIsNotNone(result_lower, "Lowercase 'hello' should be found in index") + + # Test uppercase - should work with case sensitivity fix, fail without it + result_upper = command_index.get(["HELLO", "world"]) + + # Test mixed case - should work with case sensitivity fix, fail without it + result_mixed = command_index.get(["Hello", "world"]) + + # These should work the same as lowercase (this will FAIL without the fix) + self.assertEqual(result_lower, result_upper, "Uppercase 'HELLO' should work same as lowercase 'hello'") + self.assertEqual(result_lower, result_mixed, "Mixed case 'Hello' should work same as lowercase 'hello'") + + # Clean up + del INDEX[CommandIndex._COMMAND_INDEX_VERSION] + del INDEX[CommandIndex._COMMAND_INDEX_CLOUD_PROFILE] + del INDEX[CommandIndex._COMMAND_INDEX] + @mock.patch('importlib.import_module', _mock_import_lib) @mock.patch('pkgutil.iter_modules', _mock_iter_modules) @mock.patch('azure.cli.core.commands._load_command_loader', _mock_load_command_loader)