我有一个应用程序使用GLib的命令行选项解析器来处理命令行参数(如here所述)。
我发现每个选项的描述必须非常短 - 为了适应标准大小的终端宽度(当使用--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 :(得分:0)
我有完全相同的问题。目前我正在使用ghetto修复添加空格。然而,这不适用于参数描述(而不仅仅是描述,即最后打印的内容)。如果你添加新行来打破参数描述,那么前进参数的间距就会搞乱。