>> Learn how to create Azure CLI extensions
in this episode of Azure Tips and Tricks.
Azure CLI extensions enable you to
add functionality to the Azure CLI.
Let's create one. We need a couple of things to start with.
First, we need a local installation of the Azure CLI.
You can get an installation package from this website.
The URL is included in the description of this video.
This can take a while, so I'll speed up the video.
The Azure CLI is available for
Windows and also for Mac OS and Linux.
It's truly cross-platform and it's even open source,
so you can tinker with it if you want.
There we go. We'll use that later.
We also need Python to be installed
because CLI extensions are created in Python.
You can get it here.
This is also available for all platforms,
and in Windows it's important to click this so
that Python is added to the path. All right.
There it goes and again I'll speed it up and that's it.
We'll start by creating a folder structure.
I've already done that.
This folder contains the extension.
It has two files in it,
a setup.py file which is a Python file and a setup.config file.
It also has an azext_tipsextension folder.
The last part of the folder name should match your extension name,
and in that folder there should be an init.py file. All right.
So, let's open these folders with
Visual Studio Code, my favorite editor.
In here, we need to install an extension to be
able to use Python. That's this one.
Let's install it. After that,
we reload the editor.
Look how fast it is and I'm running this on Windows,
but you can also run VS Code on Mac OS and Linux.
So now that I have the Python extension installed,
I need to select an interpreter for Python.
This enables IntelliSense and other editor features. All right.
One last thing. Let's open a Python terminal,
and from here I'll install the wheel extension with this command.
We need Python wheel to compile the extension into a wheel file.
This is a package format that the CLI uses for extensions.
That's it. Let's edit the files.
First up is setup.py.
Here, I'll paste in this code.
This sets up all of the metadata for
the extension like the extension name and description.
Next is setup.cfg that should have this code in it,
which helps us to build the actual wheel package.
Finally, we go to the init.py file. Here we go.
This now contains the actual code for the extension.
This is the functionality.
In this case, the extension will
interpret the words gimme and tips.
When it sees those words,
it fires the showtipsurl method which
prints this line of texts and that's it.
Now, I need to save the changes to the files which I can do here.
Now I open the terminal again so that we compile the code.
We do that with this command and there it goes. Let's see.
We now have a dist folder and in there is a WHL file,
which is the wheel package that contains
the extension. Let's try it out.
Here we are in the Azure CLI that we've installed earlier.
This is running on my local machine.
First, we need to install the extension.
You can do that just like adding
any other extension with the extension add commands,
but now we point to the source which is at
this local path and there we go.
Yes. So now when I type az gimme tips,
I get this back: the complete list of Azure Tips and Tricks.
Cool, right? Azure CLI extensions are
really powerful and it is easy to create one yourself.
Go and try it out.