Skip to content
Closed
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
22 changes: 4 additions & 18 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}",
Expand All @@ -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",
Expand All @@ -47,11 +38,6 @@
"--help"
],
"console": "integratedTerminal",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
}
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down