microsoft / vscode-azurecli

VS Code extension for the Azure CLI 2.0
MIT License
71 stars 46 forks source link

What is the usecase for this extension? #57

Closed sanderobdeijn closed 5 years ago

sanderobdeijn commented 5 years ago

Is this extension and the .azcli file format meant as a sandbox environment to experiment with the Azure CLI or as a way to automate your Azure deployments?

I first thought the latter option. But then I was wondering how to add variables and control structures to scripts. I could use bash or PowerShell format and could tell the shell to execute it. But if the file extension is .azcli how does PowerShell or bash know which files are in bash or PowerShell format.

I was hoping that .azcli was a multi-platform way of automating Azure CLI deployments. But it seems it is more meant as a sandbox environment or am I wrong?

chrisdias commented 5 years ago

Hi - good questions. In general, the extension makes it more natural to write azure cli scripts in VS Code itself, as compared to the command line. When the extension is activated, you get completions, quick info, and even completions based on your azure resources (e.g. it will show you a list of resource groups you have defined in Azure).

Language Services are activated based on the type of file in VS Code. When you open a .py file, the Python language service is started. Azure CLI scripts are generally written in traditional shell script files (e.g. .sh), so this extension wouldn't normally be activated. That's why we invented the .azcli file extension. If you write your scripts in a file with that extension, this language service is activated and you get completions, colorization, etc.

Ideally, you would be able to mix the language services (e.g. traditional script commands along with azure cli commands and get the right experience for either), but thats a tough nut to crack :). What you can do is switch between language services by changing the Language Mode. If you've got a .sh file open, click in the lower right corner of VS Code where it says "shell script" and then pick "Azure CLI Scrapbook". That will engage this extension while you are writing azure cli commands and when you want to switch back, do the same thing and pick "shell script".

image

To execute the commands, you can simply invoke the "Azure ClI: Run Line in Editor" command and will shell out appropriately and show the results side by side in the editor. You can also say "Azure CLI: Run line in Terminal" and that will take the selected line, open a new terminal (with the default shell you have - ps, sh, zsh) and send the text of the line to the terminal and execute it.

hope this helps!