2013-08-02 33 views
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. 

我可以通过计算我的选项描述的每一行所需的长度来手动获得上述结果。然后我可以手动在字符串中输入换行符和空格来获得正确的缩进。但这似乎是一个非常粗略的方法,并且我确信格式化输出必须有更好更省时的方式。

我敢肯定,这个问题一定出现之前,其他人,但我还没有找到解决方案,有没有人知道更好的方式来获得更好的格式?

+0

提交一个bug,附上一个补丁:)并且ping邮件列表来检查它 - 如果它是好的(而不是太多的代码斧,它应该进入) – drahnr

回答

0

我有完全相同的问题。目前我正在使用增加空格的贫民窟修复程序。然而,这对于参数描述是不可能的(而不仅仅是最后打印的描述)。如果添加换行符以破坏参数描述,则前后参数的间距会混乱。