2
我有一个应用程序使用GLib的命令行选项解析器来处理命令行参数(如描述here)。GLib命令行选项解析器 - 长条目描述
我发现每个选项条目的描述必须非常短 - 以适应标准大小终端的宽度(当应用程序使用--help参数调用时)。如果某个选项的描述太长,则它会环绕,这看起来很糟糕。有没有一种可以接受的方式来整理这些?
例如,这里是从我的应用程序输出的帮助的哪一部分看起来像一个80字符宽的终端窗口:
Application Options:
-i, --ip-addr Sets the IP address to which the video strea
ms will be sent. If this option is not used then the default IP address of 127.0
.0.1 is used.
-p, --port Sets the port to send the video streams to.
If not chosen this defaults to 1234.
理想的情况下它会是这个样子:
Application Options:
-i, --ip-addr Sets the IP address to which the video
streams will be sent. If this option is not
used then the default IP address of
127.0.0.1 is used.
-p, --port Sets the port to send the video streams to.
If not chosen this defaults to 1234.
我可以通过计算我的选项描述的每一行所需的长度来手动获得上述结果。然后我可以手动在字符串中输入换行符和空格来获得正确的缩进。但这似乎是一个非常粗略的方法,并且我确信格式化输出必须有更好更省时的方式。
我敢肯定,这个问题一定出现之前,其他人,但我还没有找到解决方案,有没有人知道更好的方式来获得更好的格式?
提交一个bug,附上一个补丁:)并且ping邮件列表来检查它 - 如果它是好的(而不是太多的代码斧,它应该进入) – drahnr