powershell indentation

后端 未结 6 1638
小蘑菇
小蘑菇 2021-02-14 12:05

I\'m writing a large script that deploys an application. This script is based on several nested function calls.

Is there any way to \"ident\" the output based on the dep

6条回答
  •  不知归路
    2021-02-14 12:40

    You can override Write-Host to write your indents before calling the original with the '&' operator and the namespace. You might be able to derive the amount of indentation from the current stack scope, but a global variable gives you more control.

    $global:writeHostIndent
    
    function Write-Host
    {
        Microsoft.PowerShell.Utility\Write-Host (' ' * $global:writeHostIndent) -NoNewline
        & 'Microsoft.PowerShell.Utility\Write-Host' $args
    }
    

提交回复
热议问题