CLI 实用程序帮助文件的最佳实践

发布于 2024-12-25 11:56:49 字数 156 浏览 4 评论 0原文

我已经完成了一个通过 getopt_long 解析参数的命令行实用程序。为了总结一切,我需要实现一个 -h 或 --help 开关,它将打印出参数列表以及描述和默认值。

是否有一个 GNU 框架可供我使用?如果没有,我意识到有几种方法可以手动完成此操作。通常被认为最好的方法是什么?

I've finished implementing a command-line utility that parses arguments via getopt_long. To wrap things up, I need to implement a -h or --help switch that will print out the list of arguments as well as descriptions and default values.

Is there a GNU framework that I can utilize for this? If not, I realize that there are several ways I can do this manually. What's generally seen as the best approach?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱情眠于流年 2025-01-01 11:56:49

您可以使用

#include <getopt.h>
int getopt_long(int argc, char * const argv[],
           const char *optstring,
           const struct option *longopts, int *longindex);

man 3 getopt_long 了解如何使用它。

关于在 --help option 的输出中打印什么,您可以阅读

GNU 编码标准

4.7.2 '--help'

http ://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp

You can use

#include <getopt.h>
int getopt_long(int argc, char * const argv[],
           const char *optstring,
           const struct option *longopts, int *longindex);

See man 3 getopt_long on how to use it.

And on what to print in the output of your --help option, you can read

GNU Coding Standards

4.7.2 ‘--help’

http://www.gnu.org/prep/standards/standards.html#g_t_002d_002dhelp

我做我的改变 2025-01-01 11:56:49

argp_parse() 是当前用于参数解析的 gnu 框架。它取代了 getopt() 和 getopt_long(),后者现在应该被认为是过时的。

argp_parse() is the current gnu framework for argument parsing. It replaces getopt() and getopt_long(), which should now be considered obsolete.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文