microsoft / knack

Knack - A Python command line interface framework
https://pypi.python.org/pypi/knack
MIT License
347 stars 95 forks source link

Config file value ignored by command validation code #261

Closed warren-jones closed 2 years ago

warren-jones commented 2 years ago

I want to use the Azure CLI’s built-in missing-required-parameter validation feature for parameters that are specific to our CLI extension, but I’m only getting it to work on their core parameters like "group" and "location". Is there a way to tell the Knack infrastructure to be aware of the setting of a parameter default, so the [Required] annotation goes away on help, and the parameter can be omitted from the command line? I am able to add my parameters to the [defaults] section of the config file, but they are ignored. Am I missing something?

How do I tell Knack to handle an Azure CLI extension command parameter the same way an Azure CLI core command parameter is handled, in regard to a default saved in the config file and command validation?

warren-jones commented 2 years ago

I got my answer! Jiashuo Li replied:

“Can you try leveraging the configured_default argument and see if that works? Similar to --location --group: https://github.com/Azure/azure-cli/blob/bcb291ad55218dd8d7d582245d4fe97beb916309/src/azure-cli-core/azure/cli/core/commands/parameters.py#L242