ifquery: add --pretty-print
This commit is contained in:
parent
cd2d35c6a2
commit
1a650a126e
1 changed files with 13 additions and 2 deletions
|
@ -56,6 +56,8 @@ print_interface(struct lif_interface *iface)
|
||||||
else
|
else
|
||||||
printf(" %s %s\n", entry->key, (const char *) entry->data);
|
printf(" %s %s\n", entry->key, (const char *) entry->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -72,6 +74,7 @@ usage()
|
||||||
printf(" -a, --auto only match against interfaces hinted as 'auto'\n");
|
printf(" -a, --auto only match against interfaces hinted as 'auto'\n");
|
||||||
printf(" -I, --include PATTERN only match against interfaces matching PATTERN\n");
|
printf(" -I, --include PATTERN only match against interfaces matching PATTERN\n");
|
||||||
printf(" -X, --exclude PATTERN never 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);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -80,6 +83,7 @@ struct match_options {
|
||||||
bool is_auto;
|
bool is_auto;
|
||||||
char *exclude_pattern;
|
char *exclude_pattern;
|
||||||
char *include_pattern;
|
char *include_pattern;
|
||||||
|
bool pretty_print;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -103,7 +107,10 @@ list_interfaces(struct lif_dict *collection, struct match_options *opts)
|
||||||
fnmatch(opts->include_pattern, iface->ifname, 0))
|
fnmatch(opts->include_pattern, iface->ifname, 0))
|
||||||
continue;
|
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'},
|
{"auto", no_argument, 0, 'a'},
|
||||||
{"include", required_argument, 0, 'I'},
|
{"include", required_argument, 0, 'I'},
|
||||||
{"exclude", required_argument, 0, 'X'},
|
{"exclude", required_argument, 0, 'X'},
|
||||||
|
{"pretty-print", no_argument, 0, 'P'},
|
||||||
{NULL, 0, 0, 0}
|
{NULL, 0, 0, 0}
|
||||||
};
|
};
|
||||||
struct match_options match_opts = {};
|
struct match_options match_opts = {};
|
||||||
|
@ -127,7 +135,7 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
for (;;)
|
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)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -153,6 +161,9 @@ main(int argc, char *argv[])
|
||||||
case 'X':
|
case 'X':
|
||||||
match_opts.exclude_pattern = optarg;
|
match_opts.exclude_pattern = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'P':
|
||||||
|
match_opts.pretty_print = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue