Python:PowerShell 命令行参数解析器

Python: PowerShell command-line arguments parser

我想知道是否有开源 Python 项目来解析 PowerShell 命令行参数?

我知道 Python 有内置模块 argparse 可以解析命令行参数,但使用 PowerShell 参数:

例如,在 Windows 控制台上,这些都是有效的:

> powershell.exe -Command "[console]::WriteLine(\"Hello\")"
Hello
> powershell.exe -Comman "[console]::WriteLine(\"Hello\")"
Hello
> powershell.exe -cOMm "[console]::WriteLine(\"Hello\")"
Hello
> powershell.exe -c "[console]::WriteLine(\"Hello\")"
Hello

或者,如果没有开源项目来实现这种解析,您会推荐什么?

与:

parser.add_argument('-c','--command');
parser.add_argument('-domain');

'-c'、'--command'、'--com' 等都可以。 '-com' 没有。

'-domain', '-d', '--dom' 也有效。

parser.add_argument('-c','-command')

出现了一些问题,因为两个单破折号标志之间存在歧义。

argparse(基于 POSIX 标准)的理想情况是使用单破折号和字符短标记,以及双破折号长标记。

可以链接短标志;而长的允许'='`。一个“-long”落在两者之间的缝隙中;它有效,但不如预期。