私はPesterスクリプトを解析し、-Tag
パラメータから値を抽出しようとしています。誰でもこれを行う方法を知っています[System.Management.Automation.PSParser]
?私は[System.Management.Automation.PSParser]::Tokenize()
から返されたトークンをループする必要があると思っていましたが、それはかなりkludgyと思われ、-Tag
の値は非常に実用的ではない多くの異なる形式で与えられます。ASTを使用したPowerShellスクリプトの解析
私は、ブロック名がDescribe
のコレクションとそのブロックのタグのリスト(あれば)を返すことを望んでいます。
Name Tags
---- ----
Section1 {tag1, tag2}
Section2 {foo, bar}
Section3 {asdf}
Section4 {}
私が扱っているサンプルのPesterテストは以下のとおりです。
describe 'Section1' -Tag @('tag1', 'tag2') {
it 'blah1' {
$true | should be $true
}
}
describe 'Section2' -Tag 'foo', 'bar' {
it 'blah2' {
$true | should be $true
}
}
describe 'Section3' -Tag 'asdf'{
it 'blah3' {
$true | should be $true
}
}
describe 'Section4' {
it 'blah4' {
$true | should be $true
}
}
誰でもこれを解決する方法はありますか? [System.Management.Automation.PSParser]
は正しい方法ですか、それとも良い方法がありますか? PS3.0 + Language namespace ASTパーサ使用
乾杯
ありがとう@ w0xx0m。少し修正して、タグを[文字列]または[文字列[]]として引き出すことができました。 – devblackops