From 149dcbae2d12587fb687b81e3a1a4631f04db4d7 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 5 Jun 2013 19:27:03 +0200 Subject: hostinfo: add -V and --version to get the version The version is generated from the git-tags during build (setup.py) or during run time, if executed from the git repository. --- bin/hostinfo | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'bin') 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 -- cgit v1.2.3-1-g7c22