6.6 KiB
Command Guidelines
This document describes the command guidelines for 'az' and applies to both CLI command modules and extensions.
Guidelines marked (*) only apply to command modules, not extensions.
If in doubt, ask!
General Patterns
- Be consistent with POSIX tools (support piping, work with grep, awk, jq, etc.)
- Support tab completion for parameter names and values (e.g. resource names)
- All commands, command group and arguments must have descriptions
- You must provide command examples for non-trivial commands
- All commands must support all output types (json, tsv, table)
- Provide custom table outputs for commands that don't provide table output automatically
- Commands must return an object, dictionary or
None
(do not string, Boolean, etc. types) - Command output must go to
stdout
, everything else tostderr
(log/status/errors). - Log to
logger.error()
orlogger.warning()
for user messages; do not use theprint()
function - Use the appropriate logging level for printing strings. e.g.
logging.info(“Upload of myfile.txt successful”)
NOTreturn “Upload successful”
.
Command Naming and Behavior
-
Commands must follow a "[noun] [noun] [verb]" pattern
-
Multi-word subgroups should be hyphenated e.g.
foo-resource
instead offooresource
-
All command names should contain a verb e.g.
account get-connection-string
instead ofaccount connection-string
-
Avoid hyphenated command names when moving the commands into a subgroup would eliminate the need. e.g.
database show
anddatabase get
instead ofshow-database
andget-database
-
If a command subgroup would only have a single command, move it into the parent command group and hyphenate the name. This is common for commands which exist only to pull down cataloging information. e.g.
database list-sku-definitions
instead ofdatabase sku-definitions list
-
Avoid command subgroups that have no commands. This often happens at the first level of a command branch. e.g.
keyvault create
instead ofkeyvault vault create
(wherekeyvault
only has subgroups and adds unnecessary depth to the tree).Click for a full example
KeyVault has secrets, certificates, etc that exist within a vault. The existing (preferred) CLI structure looks like:
Group az keyvault: Safeguard and maintain control of keys, secrets, and certificates. Subgroups: certificate : Manage certificates. key : Manage keys. secret : Manage secrets. Commands: create : Create a key vault. delete : Delete a key vault. delete-policy: Delete security policy settings for a Key Vault. list : List key vaults. list-deleted : Gets information about the deleted vaults in a subscription. purge : Permanently deletes the specified vault. recover : Recover a key vault. set-policy : Update security policy settings for a Key Vault. show : Show details of a key vault. update : Update the properties of a key vault.
To create a vault, you simply use
az keyvault create ...
. An alternative would be to place the vault commands into a separate subgroup, like this:Group az keyvault: Safeguard and maintain control of keys, secrets, and certificates. Subgroups: certificate : Manage certificates. key : Manage keys. secret : Manage secrets. vault : Manage vaults.
Now, to create a vault, you have to use
az keyvault vault create ...
which is overly verbose adds unnecessary depth to the tree. The preferred style makes the command use more convenient and intuitive.
Standard Command Types
The following are standard names and behavioral descriptions for CRUD commands commonly found within the CLI. These standard command types MUST be followed for consistency with the rest of the CLI.
CREATE
- standard command to create a new resource. Usually backed server-side by a PUT request. 'create' commands should be idempotent and should return the resource that was created.UPDATE
- command to selectively update properties of a resource and preserve existing values. May be backed server-side by either a PUT or PATCH request, but the behavior of the command should always be PATCH-like. Allupdate
commands should be registered using thegeneric_update_command
helper to expose the three generic update properties.update
commands MAY also allow for create-like behavior (PUTCH) in cases where a dedicatedcreate
command is deemed unnecessary.update
commands should return the updated resource.SET
- command to replace all properties of a resource without preserving existing values, typically backed server-side by a PUT request. This is used when PATCH-like behavior is deemed unnecessary and means that any properties not specifies are reset to their default values.set
commands are more rare compared toupdate
commands.set
commands should return the updated resource.SHOW
- command to show the properties of a resource, backed server-side by a GET request.LIST
- command to list instances of a resource, backed server-side by a GET request. When there are multiple "list-type" commands within an SDK to list resources at different levels (for example, listing resources in a subscription vice in a resource group) the functionality should be exposed by have a single list command with arguments to control the behavior. For example, if--resource-group
is provided, the command will calllist_by_resource_group
; otherwise, it will calllist_by_subscription
.DELETE
- command to delete a resource, backed server-side by a DELETE request. Delete commands return nothing on success.
Non-standard Commands
For commands that don't conform to one of the above-listed standard command patterns, use the following guidance.
- (*) Don't use single word verbs if they could cause confusion with the standard command types. For example, don't use
get
ornew
as these sound functionally the same asshow
andcreate
respectively, leading to confusion as to what the expected behavior should be. - (*) Descriptive, hyphenated command names are often a better option than single verbs.
Coding Practices
- All code must support Python 2 & 3. The CLI supports 2.7, 3.4, 3.5 and 3.6
- PRs to Azure/azure-cli and Azure/azure-cli-extensions must pass CI
- (*) Code must pass style checks with pylint and pep8
- (*) All commands should have tests