diff options
-rwxr-xr-x | bin/hostinfo | 18 | ||||
-rw-r--r-- | contrib/bash-completion | 2 |
2 files changed, 13 insertions, 7 deletions
diff --git a/bin/hostinfo b/bin/hostinfo index 5cb4247..a25d719 100755 --- a/bin/hostinfo +++ b/bin/hostinfo @@ -68,14 +68,17 @@ def find_host(host): return None +def print_help(self_name): + print('Usage: %s <host> [info]' % self_name) + def main(): self_name = sys.argv.pop(0) - file = oneline = keys = verbose = nospaces = False + file = oneline = keys = verbose = nospaces = help = False try: - optlist, args = getopt.gnu_getopt(sys.argv, 'ofkvn', + optlist, args = getopt.gnu_getopt(sys.argv, 'ofkvnh?', ['oneline', 'file', 'keys', 'verbose', - 'nospaces']) + 'nospaces', 'help']) opts = {} for key, value in optlist: opts[key] = value @@ -85,14 +88,17 @@ def main(): keys = any([o in opts for o in ['--keys', '-k']]) verbose = any([o in opts for o in ['--verbose', '-v']]) nospaces = any([o in opts for o in ['--nospaces', '-n']]) + help = any([o in opts for o in ['--help', '-h', '-?']]) except getopt.GetoptError, e: print("Error: %s" % e) print args = [] - if len(args) < 1: - print('Usage: %s <host> [info]' % self_name) - sys.exit(1) + if help or len(args) < 1: + print_help(self_name) + if not help: + sys.exit(1) + sys.exit(0) path = find_host(args[0]) if path is None: diff --git a/contrib/bash-completion b/contrib/bash-completion index 31bc6f8..0c8fb78 100644 --- a/contrib/bash-completion +++ b/contrib/bash-completion @@ -15,6 +15,6 @@ _hostinfo() { _completion="$(hostinfo --keys $arg 2>/dev/null)" fi - COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys $_completion" -- $cur ) ) + COMPREPLY=( $( compgen -W "-o --oneline -f --file -k --keys -h -? --help $_completion" -- $cur ) ) } complete -F _hostinfo hostinfo |