From 1a650a126eadbc1fd00e596cf37acfb80535f547 Mon Sep 17 00:00:00 2001 From: Ariadne Conill Date: Sat, 18 Jul 2020 19:34:38 -0600 Subject: [PATCH] ifquery: add --pretty-print --- cmd/ifquery.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cmd/ifquery.c b/cmd/ifquery.c index 07186d5..1a01cbf 100644 --- a/cmd/ifquery.c +++ b/cmd/ifquery.c @@ -56,6 +56,8 @@ print_interface(struct lif_interface *iface) else printf(" %s %s\n", entry->key, (const char *) entry->data); } + + printf("\n"); } void @@ -72,6 +74,7 @@ usage() printf(" -a, --auto only match against interfaces hinted as 'auto'\n"); printf(" -I, --include PATTERN only match against interfaces matching PATTERN\n"); printf(" -X, --exclude PATTERN never match against interfaces matching PATTERN\n"); + printf(" -P, --pretty-print pretty print the interfaces instead of just listing\n"); exit(1); } @@ -80,6 +83,7 @@ struct match_options { bool is_auto; char *exclude_pattern; char *include_pattern; + bool pretty_print; }; void @@ -103,7 +107,10 @@ list_interfaces(struct lif_dict *collection, struct match_options *opts) fnmatch(opts->include_pattern, iface->ifname, 0)) continue; - printf("%s\n", iface->ifname); + if (opts->pretty_print) + print_interface(iface); + else + printf("%s\n", iface->ifname); } } @@ -119,6 +126,7 @@ main(int argc, char *argv[]) {"auto", no_argument, 0, 'a'}, {"include", required_argument, 0, 'I'}, {"exclude", required_argument, 0, 'X'}, + {"pretty-print", no_argument, 0, 'P'}, {NULL, 0, 0, 0} }; struct match_options match_opts = {}; @@ -127,7 +135,7 @@ main(int argc, char *argv[]) for (;;) { - int c = getopt_long(argc, argv, "hVi:LaI:X:", long_options, NULL); + int c = getopt_long(argc, argv, "hVi:LaI:X:P", long_options, NULL); if (c == -1) break; @@ -153,6 +161,9 @@ main(int argc, char *argv[]) case 'X': match_opts.exclude_pattern = optarg; break; + case 'P': + match_opts.pretty_print = true; + break; } }