Invoke-Formatter
Formats a script text based on the input settings or default settings.
Sintaxe
Default (Predefinição)
Invoke-Formatter
[-ScriptDefinition] <string>
[[-Settings] <Object>]
[[-Range] <int[]>]
[<CommonParameters>]
Description
The Invoke-Formatter
cmdlet takes a string input and formats it according to defined settings. If
no Settings parameter is provided, the cmdlet assumes the default code formatting settings as
defined in Settings/CodeFormatting.psd1
.
Exemplos
EXAMPLE 1 - Format the input script text using the default settings
$scriptDefinition = @'
function foo {
"hello"
}
'@
Invoke-Formatter -ScriptDefinition $scriptDefinition
function foo {
"hello"
}
EXAMPLE 2 - Format the input script using the settings defined in a hashtable
$scriptDefinition = @'
function foo {
"hello"
}
'@
$settings = @{
IncludeRules = @("PSPlaceOpenBrace", "PSUseConsistentIndentation")
Rules = @{
PSPlaceOpenBrace = @{
Enable = $true
OnSameLine = $false
}
PSUseConsistentIndentation = @{
Enable = $true
}
}
}
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings $settings
function foo
{
"hello"
}
EXAMPLE 3 - Format the input script text using the settings defined a `.psd1` file
Invoke-Formatter -ScriptDefinition $scriptDefinition -Settings /path/to/settings.psd1
Parâmetros
-Range
The range within which formatting should take place. The value of this parameter must be an array of four integers. These numbers must be greater than 0. The four integers represent the following four values in this order:
- starting line number
- starting column number
- ending line number
- ending column number
Propriedades dos parâmetros
Tipo: | Int32[] |
Default value: | None |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 3 |
Obrigatório: | False |
Valor do pipeline: | True |
Valor do pipeline por nome de propriedade: | True |
Valor dos restantes argumentos: | False |
-ScriptDefinition
The text of the script to be formatted represented as a string. This is not a ScriptBlock object.
Propriedades dos parâmetros
Tipo: | String |
Default value: | None |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 1 |
Obrigatório: | True |
Valor do pipeline: | True |
Valor do pipeline por nome de propriedade: | True |
Valor dos restantes argumentos: | False |
-Settings
A settings hashtable or a path to a PowerShell data file (.psd1
) that contains the settings.
Propriedades dos parâmetros
Tipo: | Object |
Default value: | CodeFormatting |
Suporta carateres universais: | False |
NãoMostrar: | False |
Conjuntos de parâmetros
(All)
Position: | 2 |
Obrigatório: | False |
Valor do pipeline: | True |
Valor do pipeline por nome de propriedade: | True |
Valor dos restantes argumentos: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Saídas
String
The formatted string result.