Making the most out of the Azure CLI Interactive Mode
The power of the Azure CLI
The Azure CLI is a very powerful tool. You can use it to do basically anything in Azure from the command prompt, including creating and deleting resources like Web Apps and VMs. You can use the Azure CLI from your local computer or from the Azure Cloud Shell.
In this post, we'll explore the interactive mode of the Azure CLI. This is a special mode that enhances the behavior of the CLI.
Prerequisites
If you want to follow along, you'll need the following:
- An Azure subscription (If you don't have an Azure subscription, create a free account before you begin)
- The Azure CLI. You can download it for Windows, Linux or Mac. Or you can use the Azure Cloud Shell
Using the Azure CLI Interactive Mode
Let's take a look at the Azure CLI interactive mode. We'll use the Azure Cloud Shell for this and you can also use an Azure CLI that you run on your local machine.
- Open Azure Cloud Shell, https://shell.azure.com/
- Type az interactive to start the interactive mode
(Azure CLI interactive mode)
Autocomplete and examples
Azure CLI interactive mode helps you to be more productive. When you use it for a CLI command, like webapp show, it will automatically complete your command. It also shows you which parameters are available for the command and what the parameters mean (number 1 in the image).
You also get a description of what the command does. For instance, for the webapp show command, it shows that this command will "Get the details of a web app" (number 2 in the image).
And on top of all of that, the interactive mode also shows examples of how you can use the command (number 3 in the image).
(Azure CLI interactive mode)
Scoping
When you use the interactive mode, you don't have to type az in front of your command. This is because this mode is already scoped to the az command. And you can scope to other commands as well. If you are working with Web Apps for instance, and don't want to type webapp for every command, you can scope to webapp by typing %%webapp. You can also scope deeper by scoping to the webapp create command with %%create. You can go back in scope by typing %%.. to go up one level or by typing %% to go back to the root scope.
(Scoping in the Azure CLI interactive mode)
Query
You can use the Azure CLI to query JSON results from commands that you run. For instance, when you create a Resource Group, the result is a JSON string that contains the data for that Resource Group, including its id and name.
In the Azure CLI interactive mode, you can use the JSON results of a previous command in other commands with JMESPath queries. For instance, when you create a Web App, you can give it the name of a Resource Group that you've created in a previous command with "?? name":
(JMESPath query in the Azure CLI interactive mode)
External commands
You can run shell commands without leaving the Azure CLI interactive mode, like a bash command. You can run shell commands by typing #[cmd], for instance, #mkdir to create a new directory.
(External commands in the Azure CLI interactive mode)
Conclusion
You can be very productive in Azure with the Azure CLI. And you can be even more productive when you use the Azure CLI interactive mode. Go and check it out!
Live streaming software development
On a side note - If you like my articles, then you might enjoy another project that I'm working on for live streaming. Check out my channel and hit the follow button to know when I'm live.
Top comments (0)