diff options
author | Alexander Sulfrian <alexander@sulfrian.net> | 2013-06-05 19:25:29 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander@sulfrian.net> | 2013-06-05 19:25:29 +0200 |
commit | 1b850e286810a17668ccfa4aedbab6d6077608f8 (patch) | |
tree | a8f99cd6a21c652baa865651c5550e20c4a211d3 | |
parent | dcb4804af80238935a34ca9e3d37bc88335eac7f (diff) | |
download | tools-1b850e286810a17668ccfa4aedbab6d6077608f8.tar.gz tools-1b850e286810a17668ccfa4aedbab6d6077608f8.tar.bz2 tools-1b850e286810a17668ccfa4aedbab6d6077608f8.zip |
hostinfo: add --only-names option
With the --only-names option only the hostnames of the matching hosts
are printed. This is default with negative match (there is nothing to
print if the key does not exists).
-rwxr-xr-x | bin/hostinfo | 8 | ||||
-rw-r--r-- | contrib/bash-completion | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/bin/hostinfo b/bin/hostinfo index c5bb9c3..98c2162 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -90,8 +90,12 @@ def print_search(basepath, flags, search): data = _get_data(os.path.join(basepath, host)) key, result = match(data, search) if result is not None: + if flags.only_names: + print(_get_label(host)) + continue + if key is None: - print(host) + print(_get_label(host)) else: p = printer.Printer(data, flags) p.info(key, label=_get_label(host), maxlength=max(length)) @@ -192,6 +196,8 @@ def main(): help="lists all available hosts") parser.add_argument("-s", "--short", action="store_true", help="remove the domain from the output") + parser.add_argument("--only-names", action="store_true", + help="only print the hostname of the matching entries") args = parser.parse_args() if args.path: diff --git a/contrib/bash-completion b/contrib/bash-completion index 5315d83..333bf0e 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -49,7 +49,8 @@ _hostinfo() { COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help -p --path -n --nospaces -l --hosts -s --short - -v --verbose $_completion" -- $cur ) ) + -v --verbose --only-names + $_completion" -- $cur ) ) fi } complete -F _hostinfo hostinfo |