From ad32229c673b9ff01249590d0e042f1f1ba346ed Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 5 Jun 2013 19:26:23 +0200 Subject: hostinfo: add --details option With --details the whole hostinfo entry is displayed for all matching hosts. --- bin/hostinfo | 13 +++++++++---- contrib/bash-completion | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/hostinfo b/bin/hostinfo index 98c2162..0a65443 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -94,11 +94,14 @@ def print_search(basepath, flags, search): print(_get_label(host)) continue - if key is None: - print(_get_label(host)) + p = printer.Printer(data, flags) + if flags.details: + p.info(None, label=_get_label(host), maxlength=max(length)) else: - p = printer.Printer(data, flags) - p.info(key, label=_get_label(host), maxlength=max(length)) + if key is None: + print(_get_label(host)) + else: + p.info(key, label=_get_label(host), maxlength=max(length)) def print_info(path, flags, key=None): data = _get_data(path) @@ -198,6 +201,8 @@ def main(): help="remove the domain from the output") parser.add_argument("--only-names", action="store_true", help="only print the hostname of the matching entries") + parser.add_argument("-d", "--details", action="store_true", + help="print details about matching hosts") args = parser.parse_args() if args.path: diff --git a/contrib/bash-completion b/contrib/bash-completion index 333bf0e..4d64f08 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -49,7 +49,7 @@ _hostinfo() { COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help -p --path -n --nospaces -l --hosts -s --short - -v --verbose --only-names + -v --verbose --only-names -d --details $_completion" -- $cur ) ) fi } -- cgit v1.2.3-1-g7c22