提交 a2bc2e5c 编写于 作者: Q Quentin Monnet 提交者: David S. Miller

tools: bpftool: add option parsing to bpftool, --help and --version

Add an option parsing facility to bpftool, in prevision of future
options for demanding JSON output. Currently, two options are added:
--help and --version, that act the same as the respective commands
`help` and `version`.
Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
Acked-by: NDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 b66e907c
...@@ -68,6 +68,14 @@ DESCRIPTION ...@@ -68,6 +68,14 @@ DESCRIPTION
**bpftool map help** **bpftool map help**
Print short help message. Print short help message.
OPTIONS
=======
-h, --help
Print short generic help message (similar to **bpftool help**).
-v, --version
Print version number (similar to **bpftool version**).
EXAMPLES EXAMPLES
======== ========
**# bpftool map show** **# bpftool map show**
......
...@@ -50,6 +50,14 @@ DESCRIPTION ...@@ -50,6 +50,14 @@ DESCRIPTION
**bpftool prog help** **bpftool prog help**
Print short help message. Print short help message.
OPTIONS
=======
-h, --help
Print short generic help message (similar to **bpftool help**).
-v, --version
Print version number (similar to **bpftool version**).
EXAMPLES EXAMPLES
======== ========
**# bpftool prog show** **# bpftool prog show**
......
...@@ -31,6 +31,14 @@ DESCRIPTION ...@@ -31,6 +31,14 @@ DESCRIPTION
Note that format of the output of all tools is not guaranteed to be Note that format of the output of all tools is not guaranteed to be
stable and should not be depended upon. stable and should not be depended upon.
OPTIONS
=======
-h, --help
Print short help message (similar to **bpftool help**).
-v, --version
Print version number (similar to **bpftool version**).
SEE ALSO SEE ALSO
======== ========
**bpftool-map**\ (8), **bpftool-prog**\ (8) **bpftool-map**\ (8), **bpftool-prog**\ (8)
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <bfd.h> #include <bfd.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <getopt.h>
#include <linux/bpf.h> #include <linux/bpf.h>
#include <linux/version.h> #include <linux/version.h>
#include <stdio.h> #include <stdio.h>
...@@ -215,8 +216,32 @@ static int do_batch(int argc, char **argv) ...@@ -215,8 +216,32 @@ static int do_batch(int argc, char **argv)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
static const struct option options[] = {
{ "help", no_argument, NULL, 'h' },
{ "version", no_argument, NULL, 'V' },
{ 0 }
};
int opt;
last_do_help = do_help;
bin_name = argv[0]; bin_name = argv[0];
NEXT_ARG();
while ((opt = getopt_long(argc, argv, "Vh",
options, NULL)) >= 0) {
switch (opt) {
case 'V':
return do_version(argc, argv);
case 'h':
return do_help(argc, argv);
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc < 0)
usage();
bfd_init(); bfd_init();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册