【发布时间】:2016-10-07 03:45:03
【问题描述】:
我正在尝试解析 Pester 脚本并从 -Tag 参数中提取值。任何人都知道如何使用[System.Management.Automation.PSParser]?。我在想我必须遍历从 [System.Management.Automation.PSParser]::Tokenize() 返回的令牌,但这看起来很笨拙,并且考虑到 -Tag 的值可以以许多不同的格式给出,不是很实用。
最后,我希望返回一个带有 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] 是正确的方法还是有更好的方法?
干杯
【问题讨论】:
标签: powershell parsing abstract-syntax-tree