Skip to content

Commit

Permalink
Add --help and --version options
Browse files Browse the repository at this point in the history
  • Loading branch information
rjuju committed Apr 13, 2019
1 parent 088e793 commit 8797f2d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
52 changes: 43 additions & 9 deletions powa-collector.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
#!/usr/bin/env python

import getopt
import os
import sys
from powa_collector import PowaCollector
from powa_collector import PowaCollector, getVersion

if (len(sys.argv) > 1):

def usage(rc):
"""
Show tool usage
"""
print("""Usage:
powa-collector.py
%s [ -? | --help ] [ -V | --version ]
-? | --help Show this message and exits
-v | --version Report powa-collector version and exits
See https://powa.readthedocs.io/en/latest/powa-collector/ for
more information about this tool.
""" % os.path.basename(__file__))

sys.exit(rc)


def main():
"""
Simple wrapper around PowaCollector
"""
try:
opts, args = getopt.getopt(sys.argv[1:], "?V", ["help", "version"])
except getopt.GetoptError as e:
print(str(e))
usage(1)

for o, a in opts:
if o in ("-?", "--help"):
usage(0)
elif o in ("-V", "--version"):
print("%s version %s" % (os.path.basename(__file__), getVersion()))
sys.exit(0)
else:
assert False, "unhandled option"

app = PowaCollector()
app.main()

See https://powa.readthedocs.io/en/latest/powa-collector/ for
more information about this tool.
""")
sys.exit(1)

app = PowaCollector()
app.main()
if (__name__ == "__main__"):
main()
4 changes: 4 additions & 0 deletions powa_collector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@
__VERSION_NUM__ = [int(part) for part in __VERSION__.split('.')]


def getVersion():
return __VERSION__


class PowaCollector():
def __init__(self):
self.workers = {}
Expand Down

0 comments on commit 8797f2d

Please sign in to comment.