microsoft / knack

Knack - A Python command line interface framework
https://pypi.python.org/pypi/knack
MIT License
347 stars 95 forks source link

output: Add new output mode: cmd. #271

Open eiffel-fl opened 1 year ago

eiffel-fl commented 1 year ago

Hi.

In this PR, I added a new output mode: cmd. The main goal of this output mode is to be used when running a command in a VM or VMSS, so it display the output as if it is was printed locally instead of having the output stored inside JSON object which leads to loss of formatting:

# Without cmd
$ az vmss run-command invoke ... --command-id RunShellScript --instance-id 0 --scripts 'echo "foo\tbar\tquux\ncorge"' -o json
{
  "value": [
    {
      "code": "ProvisioningState/succeeded",
      "displayStatus": "Provisioning succeeded",
      "level": "Info",
      "message": "Enable succeeded: \n[stdout]\nfoo\tbar\tquux\ncorge\n\n[stderr]\n",
      "time": null
    }
  ]
}
# With cmd
$ az vmss run-command invoke ... --command-id RunShellScript --instance-id 0 --scripts 'echo "foo\tbar\tquux\ncorge"' -o cmd
foo     bar     quux
corge

If you have any comments to make this contribution better, feel free to share.

Best regards and thank you in advance.