azcli-npm
node module wrapper around azure cli 2.x
Install
npm i -S azcli-npm
Usage
Basic usage and CLI version reporting
var cli = console
Set configuration property overrides
var cli = <IAzOptions> minVersion: '2.0.0' maxVersion: '2.1' ignoreVersion: false console
Login with a SP and secret
; var cli = clicli
Login with a SP and PEM certificate
; var cli = clicli
Set Subscription
; var cli = cli
List VMs via json object
; var cli = var results =cli start execJson<any> results cli
Unit test/mocking
If you want to incoroporate this module into your unit tests we provide a built-in mocking system, or you can roll your own.
To roll your own create a class that implements ShellRunner and its constructor. Then just override all the public facing functions
{ supershellPath }; //Now you can use this class as the shell override type when creating a new cli()var cli = <IAzOptions> shellRunner: MyMock
You can instead use the built-in mocking system which provides helpers for setting expected response types for commands
let options = <IAzOptions> shellRunner: MockRunnerlet wrapper = //grab the cli instance injected with MockRunnerlet runner = wrappercli //the mr object is used to inject responses before commands are executed//these functions return the cli instance so you can directly chain off itlet mr = wrappermr //now you can assign response objects before calling commands //this will be the result for the setSubscription() callmr //-> returns wrapper.cli //this creates a custom result for the 'webapp list' cmd after let results = mr // -> returns wrapper.cli so we can chain from it start execJson<any> console //You can also use this without chaining if you have commands pre-wrappedmrmr //this chain will consume the two mock responses aboverunner