Azure / Azure/azure-cli

`three_state_flag` generates incorrect default values

Open
#13,154 3 comments 0 reactions 1 assignee Claimed by @houk-ms View on GitHub
act-platform-engineering-squad Core feature-request
Dominant language
Python
Stars
4.6k
Forks
3.5k
Avg merge
3d 2h
Merged PRs (30d)
60

Description

This is my code:
```python
c.argument('enabled_for_deployment', arg_type=get_three_state_flag(), default=False, help='Allow Virtual Machines to retrieve certificates stored as secrets from the vault.')
c.argument('enabled_for_disk_encryption', arg_type=get_three_state_flag(), default=False, help='Allow Disk Encryption to retrieve secrets from the vault and unwrap keys.')
c.argument('enabled_for_template_deployment', arg_type=get_three_state_flag(), default=False, help='Allow Resource Manager to retrieve secrets from the vault.')
c.argument('enable_rbac_authorization', arg_type=get_three_state_flag(), default=False, help='Enable RBAC authorization for the vault, and all contained entities.')
c.argument('enable_soft_delete', arg_type=get_three_state_flag(), default=True, help='Enable vault deletion recovery for the vault, and all contained entities')
c.argument('enable_purge_protection', arg_type=get_three_state_flag(), default=True, help='Prevents manual purging of deleted vault, and all contained entities')
```

This is the generated help message:
```
az keyvault create -h

--enable-purge-protection : Prevents manual purging of deleted vault, and all contained
entities. Allowed values: false, true. Default: 1.
--enable-rbac-authorization : Enable RBAC authorization for the vault, and all contained
entities. Allowed values: false, true.
--enable-soft-delete : Enable 'soft delete' functionality for this key vault and
all contained entities. If omitted, it will be set to true
by default. Once set to true, it cannot be reverted to
false. Allowed values: false, true. Default: 1.
--enabled-for-deployment : Allow Virtual Machines to retrieve certificates stored as
secrets from the vault. Allowed values: false, true.
--enabled-for-disk-encryption : Allow Disk Encryption to retrieve secrets from the vault and
unwrap keys. Allowed values: false, true.
--enabled-for-template-deployment : Allow Resource Manager to retrieve secrets from the vault.
Allowed values: false, true.

```

As you can see, if you specify `True` as default value, you will get `1` in help message, if you specify `False`, you will get nothing.

Also, if I use `default='false'` or `default='true'`, the help message will be correctly generated. But the value inside will all be `True`.

Not sure whether this would affect the docs page.

```
CLI/Core Version: 2.4.0
Platform: Windows 10
Python: 3.7.6
```

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.