A PoC of Azure CLI using Rust.
**Try it**: https://magodo.github.io/az-rs
# Introduction
This is a simplified Azure CLI implementation, which execute the command the user specified, or just display the simplified help message (via `-h` or `--help`).
The CLI works dynamically by relying on the metadata for Azure APIs (which is generated by another project). This means only when the target Azure resource's API has its metadata file available, this CLI can perceive and show the available operations of that resource in the help message, or correctly handle user's input to manage that resource.
**NOTE** Currently, this CLI implementation only supports the resource group API.
# API Metadata
The API metadata is a description of the Azure API, which is generated from Azure Swagger spec, by another project. In runtime, these metadata files can be read from a specific folder from filesystem, or they can be embedded to the CLI binary. This behavior is controled by the feature `embed-api`. Additionally, if the crate is targeting to `wasm32-unknown-unknown`, then it will always embed the metadata to the WASM binary, regardless the feature `embed-api`.
# Build
## Pre-requisite
In the root folder, create a folder `metadata`, which is meant to store the API metadata files, to be used either during build time (if embedded), or during runtime. Currently, this folder path is hardcoded.
## Features
This package provides the following `features`:
- `embed-api`: Control whether to embed the API metadata with the binary. This only applies when the target is not `wasm32-unknown-unknown` (which always embeds).
## Native Build
The simplified CLI resides in the example: `src/bin/azure.rs`.
You can build it via (optionally add the `--features embed-api` if needed):
```
cargo install --bin azure --path .
```
## WASM Build
Follow https://rustwasm.github.io/book/game-of-life/setup.html to setup the Rust toolchain and `wasm-pack`.
Then you can build the crate to a WASM by:
```
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack build --target web --features runtime-web
```
(Note that the `RUSTFLAGS` thing is required for the `getrandom` crate)
Then go to the `www` folder and start a HTTP server, e.g.
```
$ npm install
$ npm run dev
```