You are viewing a plain text version of this content. The canonical link for it is here.
Posted to tashi-commits@incubator.apache.org by st...@apache.org on 2012/07/27 04:17:38 UTC

svn commit: r1366274 - /incubator/tashi/trunk/src/tashi/client/test.py

Author: stroucki
Date: Fri Jul 27 04:17:37 2012
New Revision: 1366274

URL: http://svn.apache.org/viewvc?rev=1366274&view=rev
Log:
test: more learning on optparse

Modified:
    incubator/tashi/trunk/src/tashi/client/test.py

Modified: incubator/tashi/trunk/src/tashi/client/test.py
URL: http://svn.apache.org/viewvc/incubator/tashi/trunk/src/tashi/client/test.py?rev=1366274&r1=1366273&r2=1366274&view=diff
==============================================================================
--- incubator/tashi/trunk/src/tashi/client/test.py (original)
+++ incubator/tashi/trunk/src/tashi/client/test.py Fri Jul 27 04:17:37 2012
@@ -3,13 +3,40 @@
 import optparse
 import sys
 
+def remoteCommand(command, options):
+	print "Doing command %s options %s" % (command, options)
+	return 0
+
 def setHostState(args):
 	parser = optparse.OptionParser()
-	parser.add_option("--host")
+	parser.set_usage("%s setHostState [options]" % sys.argv[0])
+	parser.add_option("--host", help="Set the state of this host", action="store", type="string", dest="hostname")
+	parser.add_option("--state", help="Change state to this value", action="store", type="string", dest="state")
+	(options, arguments) = parser.parse_args(args)
+	print options
+	print arguments
+	if options.hostname is None or options.state is None:
+		print "A mandatory option is missing\n"
+		parser.print_help()
+		sys.exit(-1)
+
+	remoteCommand("shs", options)
 	return 0
 
 def setHostNotes(args):
 	parser = optparse.OptionParser()
+	parser.set_usage("%s setHostNotes [options]" % sys.argv[0])
+	parser.add_option("--host", help="Annotate this host with the note (mandatory)", action="store", type="string", dest="hostname")
+	parser.add_option("--notes", help="Annotate the host with this note (mandatory)", action="store", type="string", dest="notes")
+	(options, arguments) = parser.parse_args(args)
+	print options
+	print arguments
+	if options.hostname is None or options.notes is None:
+		print "A mandatory option is missing\n"
+		parser.print_help()
+		sys.exit(-1)
+
+	remoteCommand("shn", options)
 	return 0
 
 cmdsdesc = (