我有一个使用 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.
通过计算出我的选项描述的每一行所需的长度,我可以手动获得上述结果。然后我可以手动在字符串中输入换行符和空格以获得正确的缩进。但这似乎是一种非常粗略的方法,我确信必须有一种更好、更省时的方式来格式化输出。
我敢肯定这个问题之前一定已经为其他人提出过,但我还没有找到解决方案,这里有没有人知道获得更好格式的更好方法?