]> xenbits.xensource.com Git - libvirt.git/commitdiff
example: Redirect --help output to stdout/stderr
authorPhilipp Hahn <hahn@univention.de>
Wed, 12 Oct 2011 15:11:58 +0000 (17:11 +0200)
committerEric Blake <eblake@redhat.com>
Wed, 12 Oct 2011 22:14:28 +0000 (16:14 -0600)
When --help is requested, print usage() to stdout.
When an illegal option is passed, print usage to stderr.

Signed-off-by: Philipp Hahn <hahn@univention.de>
examples/domain-events/events-python/event-test.py

index 9018366512a19d6375ddaaaecea344497b84f01c..5272e5693a51fb2b41b88eb912b787629663f444 100644 (file)
@@ -469,9 +469,9 @@ def myDomainEventIOErrorCallback(conn, dom, srcpath, devalias, action, opaque):
 def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, authScheme, subject, opaque):
     print "myDomainEventGraphicsCallback: Domain %s(%s) %d %s" % (dom.name(), dom.ID(), phase, authScheme)
 
-def usage():
-        print "usage: "+os.path.basename(sys.argv[0])+" [uri]"
-        print "   uri will default to qemu:///system"
+def usage(out=sys.stderr):
+    print >>out, "usage: "+os.path.basename(sys.argv[0])+" [uri]"
+    print >>out, "   uri will default to qemu:///system"
 
 def main():
     try:
@@ -483,7 +483,7 @@ def main():
         sys.exit(2)
     for o, a in opts:
         if o in ("-h", "--help"):
-            usage()
+            usage(sys.stdout)
             sys.exit()
 
     if len(args) >= 1: