diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/hostinfo | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/hostinfo b/bin/hostinfo index f1453e9..8700be7 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -5,6 +5,7 @@ import sys import argparse import yaml import os +import pkg_resources from dns import resolver, reversename OWN_DIRECTORY = os.path.dirname(os.path.abspath(os.path.realpath(__file__))) @@ -190,6 +191,20 @@ def find_host(basepath, host): return None +def print_version_and_exit(): + ver = None + try: + import version + ver = version.get_git_version() + except: + ver = pkg_resources.require("hostinfo-tools")[0].version + + if ver is None: + sys.stderr.write('Unable to identify the version information.') + sys.exit(1) + print("hostinfo-tools %s" % ver) + sys.exit(0) + def main(): basepath = '/usr/local/share/hostinfo' if 'HOSTINFO_PATH' in os.environ and os.environ['HOSTINFO_PATH'] != '': @@ -220,8 +235,13 @@ def main(): help="only print the hostname of the matching entries") parser.add_argument("-d", "--details", action="store_true", help="print details about matching hosts") + parser.add_argument("-V", "--version", action="store_true", + help="only print the version number and exit") args = parser.parse_args() + if args.version: + print_version_and_exit() + if args.path: basepath = args.path |