Skip to content

Commit

Permalink
add TopLevelNoCmdletBindingFound check
Browse files Browse the repository at this point in the history
for peoples like MScholtes/PS2EXE#136 ...
  • Loading branch information
steve02081504 committed Aug 6, 2024
1 parent ad134c4 commit 3ceb752
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ps12exe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,9 @@ if ($SyntaxErrors) {
$global:LastExitCode = 1
return
}
elseif (!$AST) {
$AST = [System.Management.Automation.Language.Parser]::ParseInput($Content, [ref]$null, [ref]$null)
}

# retrieve absolute paths independent if path is given relative oder absolute
if (-not $inputFile) {
Expand Down Expand Up @@ -566,6 +569,19 @@ $resourceParamKeys | ForEach-Object {
}
}

if ($AST.ParamBlock) {
$hasCmdletBinding = $false
foreach ($param in $AST.ParamBlock.Attributes) {
if ($param.TypeName.Name -eq 'CmdletBinding') {
$hasCmdletBinding = $true
break
}
}
if (!$hasCmdletBinding) {
Write-I18n Warning TopLevelNoCmdletBindingFound
}
}

. $PSScriptRoot\src\AstAnalyze.ps1
$AstAnalyzeResult = AstAnalyze $Ast
Write-Debug "AstAnalyzeResult: $(($AstAnalyzeResult|ConvertTo-Json) -split "\r?\n" -ne '' -join "`n")"
Expand Down
1 change: 1 addition & 0 deletions src/locale/en-UK.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SomeCmdletsMayNotAvailable = "Cmdlets {0} used but may not available in runtime, make sure you've checked it!"
SomeNotFindedCmdlets = "Unknown functions {0} used"
SomeTypesMayNotAvailable = "Types {0} used but may not available in runtime, make sure you've checked it!"
TopLevelNoCmdletBindingFound = "The program has a parameter block, but the parameter block does not have the CmdletBinding attribute. This may cause the final program to be unable to receive parameters."
CompilingFile = "Compiling file..."
CompilationFailed = "Compilation failed!"
OutputFileNotWritten = "Output file {0} not written"
Expand Down
1 change: 1 addition & 0 deletions src/locale/es-ES.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SomeCmdletsMayNotAvailable = "¡Se usaron cmdlets {0} pero pueden no estar disponibles en tiempo de ejecución, asegúrese de haberlos verificado!"
SomeNotFindedCmdlets = "Se usaron funciones desconocidas {0}"
SomeTypesMayNotAvailable = "¡Se usaron tipos {0} pero pueden no estar disponibles en tiempo de ejecución, asegúrese de haberlos verificado!"
TopLevelNoCmdletBindingFound = "El programa tiene un bloque de parámetros, pero el bloque de parámetros no tiene el atributo CmdletBinding. Esto puede hacer que el programa final no pueda recibir parámetros."
CompilingFile = "Compilando archivo..."
CompilationFailed = "¡Falló la compilación!"
OutputFileNotWritten = "No se escribió el archivo de salida {0}"
Expand Down
1 change: 1 addition & 0 deletions src/locale/hi-IN.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SomeCmdletsMayNotAvailable = "उपयोग किए गए Cmdlets {0} लेकिन रनटाइम में उपलब्ध नहीं हो सकते हैं, सुनिश्चित करें कि आपने उनकी जांच की है!"
SomeNotFindedCmdlets = "अज्ञात कार्यों {0} का उपयोग किया गया"
SomeTypesMayNotAvailable = "उपयोग किए गए टाइप {0} रनटाइम में उपलब्ध नहीं हो सकते हैं, सुनिश्चित करें कि आपने उनकी जांच की है!"
TopLevelNoCmdletBindingFound = "इस प्रोग्राम में एक पैरामीटर ब्लॉक है, लेकिन पैरामीटर ब्लॉक में CmdletBinding विशेषता नहीं है। इससे अंतिम प्रोग्राम पैरामीटर प्राप्त करने में असमर्थ हो सकता है।"
CompilingFile = "संकलन..."
CompilationFailed = "संकलन विफल!"
OutputFileNotWritten = "आउटपुट फ़ाइल {0} नहीं लिखी गई"
Expand Down
1 change: 1 addition & 0 deletions src/locale/ja-JP.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SomeCmdletsMayNotAvailable = "実行時に利用できない可能性のあるコマンドレット {0} が使用されています。確認してください!"
SomeNotFindedCmdlets = "未知の命令 {0} が使用されています"
SomeTypesMayNotAvailable = "実行時に利用できない可能性のある型 {0} が使用されています。確認してください!"
TopLevelNoCmdletBindingFound = "このプログラムにはパラメータブロックがありますが、パラメータブロックにCmdletBinding属性がありません。そのため、完成したプログラムがパラメータを受け取れなくなる可能性があります。"
CompilingFile = "コンパイル中..."
CompilationFailed = "コンパイルに失敗しました!"
OutputFileNotWritten = "出力ファイル {0} が書き込まれませんでした"
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-CN.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SomeCmdletsMayNotAvailable = "使用了可能会在运行时不可用的命令 {0},确保已检查它们!"
SomeNotFindedCmdlets = "使用了未知的命令 {0}"
SomeTypesMayNotAvailable = "使用了可能会在运行时不可用的类型 {0},确保已检查它们!"
TopLevelNoCmdletBindingFound = "该程序有参数块,但参数块没有CmdletBinding属性,这可能导致成品程序无法接收参数。"
CompilingFile = "编译中..."
CompilationFailed = "编译失败!"
OutputFileNotWritten = "未写入输出文件 {0}"
Expand Down

0 comments on commit 3ceb752

Please sign in to comment.