summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-05-17 13:46:06 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-05-17 15:37:46 +0200
commitd0d48d32b86ab5f5a5f75074b9b452426b30e7d5 (patch)
tree1703654cb6fbdb67fb40828c2adcab00cbb86214
parent260eef5f68b27bc7ed92e875679891b469301d13 (diff)
downloadtools-d0d48d32b86ab5f5a5f75074b9b452426b30e7d5.tar.gz
tools-d0d48d32b86ab5f5a5f75074b9b452426b30e7d5.tar.bz2
tools-d0d48d32b86ab5f5a5f75074b9b452426b30e7d5.zip
hostinfo: add help cmdline parameter
-rwxr-xr-xbin/hostinfo18
-rw-r--r--contrib/bash-completion2
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