Azure / Azure/azure-cli

'--subscription' sometimes exists sometimes not

Open
#22,330 1 comment 0 reactions 3 assignees Claimed by @jsntcy View on GitHub
act-platform-engineering-squad Auto-Assign Core feature-request Knack Request from Docs
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

**Related command**
`az account alias xxx`
`az webapp xxx`

**Describe the bug**
I am using the python code to get all the help information of commands. I find that a global parameter '--subscription' sometimes exists sometimes not. **This happens in (all?) commands from extension 'account' and 'webapp'.**

**To Reproduce**
Install azure-cli and extension 'account', run the following python code. Code is easy. It loads all the commands and see if commands 'az account alias create' has parameter '--subscription' and run it 10 times.
```
from azure.cli.core import MainCommandsLoader, AzCli
from azure.cli.core.commands import AzCliCommandInvoker
from azure.cli.core.parser import AzCliCommandParser
from azure.cli.core.file_util import create_invoker_and_load_cmds_and_args, get_all_help
from azure.cli.core._help import AzCliHelp

for i in range(10):
az_cli = AzCli(cli_name='az',
commands_loader_cls=MainCommandsLoader,
invocation_cls=AzCliCommandInvoker,
parser_cls=AzCliCommandParser,
help_cls=AzCliHelp)
create_invoker_and_load_cmds_and_args(az_cli)
help_files = get_all_help(az_cli)
command_alias_create = next((h for h in help_files if h.command == 'account alias create'), None)
print(f"[Note] 'account alias create' has {len(command_alias_create.parameters)} parameters")
print(f"[Note] 'account alias create' contains '--subscription': {'--subscription' in (p.name for p in command_alias_create.parameters)}")
```
This is the output in my side. Sometimes command 'az account alias create' has 14 parameters with '--subscription', sometimes it has 13 parameters without '--subscription'.
![image](https://user-images.githubusercontent.com/8327019/167535373-ce745e3e-5f55-49d6-8b36-157f2508ebe1.png)

**Expected behavior**
The output should always be the same (always has '--subscription' or not).

**Environment summary**
```
Python 3.9.7
{
"azure-cli": "2.35.0",
"azure-cli-core": "2.35.0",
"azure-cli-telemetry": "1.0.6",
"extensions": {
"account": "0.2.2",
"acrtransfer": "1.1.0",
"ad": "0.1.0",
"aem": "0.3.0",
"ai-examples": "0.2.5",
"aks-preview": "0.5.63",
"alertsmanagement": "0.2.2",
"alias": "0.5.2",
"amg": "0.1.0",
"application-insights": "0.1.16",
"appservice-kube": "0.1.6",
"arcappliance": "0.2.18",
"arcdata": "1.3.1",
"attestation": "0.2.0",
"authV2": "0.1.1",
"automation": "0.1.1",
"azure-batch-cli-extensions": "6.0.0",
"azure-cli-ml": "1.37.0",
"azure-devops": "0.25.0",
"azure-firewall": "0.13.0",
"azure-iot": "0.14.0",
"azurestackhci": "0.2.3",
"baremetal-infrastructure": "1.0.0",
"blockchain": "0.1.1",
"blueprint": "0.3.1",
"cli-translator": "0.3.0",
"cloud-service": "0.2.0",
"communication": "1.1.0",
"confidentialledger": "0.1.0",
"confluent": "0.4.0",
"connectedk8s": "1.2.8",
"connectedmachine": "0.4.1",
"connectedvmware": "0.1.6",
"containerapp": "0.3.1",
"cosmosdb-preview": "0.15.0",
"costmanagement": "0.2.1",
"csvmware": "0.3.0",
"custom-providers": "0.2.1",
"customlocation": "0.1.3",
"databox": "0.1.3",
"databricks": "0.8.0",
"datadog": "0.1.1",
"datafactory": "0.5.0",
"datamigration": "0.3.0",
"dataprotection": "0.3.0",
"datashare": "0.2.0",
"db-up": "0.2.7",
"deploy-to-azure": "0.2.0",
"desktopvirtualization": "0.2.0",
"dev-spaces": "1.0.6",
"diskpool": "0.2.0",
"dms-preview": "0.15.0",
"dnc": "0.1.3",
"edgeorder": "0.1.0",
"elastic": "0.1.0",
"enterprise-edge": "0.1.1",
"eventgrid": "0.4.9",
"express-route-cross-connection": "0.1.1",
"footprint": "1.0.0",
"front-door": "1.0.16",
"functionapp": "0.1.1",
"fzf": "1.0.2",
"guestconfig": "0.1.1",
"hack": "0.4.3",
"hardware-security-modules": "0.1.0",
"healthbot": "0.1.0",
"healthcareapis": "0.3.4",
"hpc-cache": "0.1.5",
"image-copy-extension": "0.2.9",
"image-gallery": "0.1.3",
"import-export": "0.1.1",
"init": "0.1.0",
"interactive": "0.4.5",
"internet-analyzer": "0.1.0rc6",
"ip-group": "0.1.2",
"k8s-configuration": "1.5.1",
"k8s-extension": "1.2.0",
"k8sconfiguration": "0.2.4",
"kusto": "0.5.0",
"log-analytics": "0.2.2",
"log-analytics-solution": "0.1.1",
"logic": "0.1.5",
"logz": "0.1.0",
"maintenance": "1.3.0",
"managementpartner": "0.1.3",
"mesh": "0.10.7",
"mixed-reality": "0.0.4",
"ml": "2.2.3",
"monitor-control-service": "0.3.0",
"netappfiles-preview": "0.3.2",
"next": "0.1.2",
"notification-hub": "0.2.0",
"offazure": "0.1.0",
"peering": "0.2.1",
"portal": "0.1.2",
"providerhub": "0.2.0",
"purview": "0.1.0",
"quantum": "0.15.0",
"quota": "0.1.0",
"rdbms-connect": "1.0.2",
"redisenterprise": "0.1.1",
"resource-graph": "2.1.0",
"resource-mover": "0.1.1",
"sap-hana": "0.6.5",
"scheduled-query": "0.5.0",
"scvmm": "0.1.4",
"sentinel": "0.1.2",
"serial-console": "0.1.1",
"spring-cloud": "3.1.3",
"ssh": "1.1.1",
"stack-hci": "0.1.4",
"storage-blob-preview": "0.6.1",
"storage-preview": "0.8.2",
"storagesync": "0.1.2",
"stream-analytics": "0.1.2",
"subscription": "0.1.4",
"support": "1.0.3",
"timeseriesinsights": "0.2.1",
"virtual-network-manager": "0.5.0",
"virtual-network-tap": "0.1.0",
"virtual-wan": "0.2.11",
"vm-repair": "0.4.3",
"vmware": "4.0.2",
"webapp": "0.4.0",
"webpubsub": "1.1.0"
}
}
```

**Additional context**
I am using this information to generate the Docs Page(https://docs.microsoft.com/en-us/cli/azure/account/alias?view=azure-cli-latest) . Currently I have to hard-code the global parameters for all commands because of this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.