Wednesday, August 22, 2012

WLST and getopt - parsing command line arguments

This is far from ideal but it works:

import getopt
env = None
password = None
list = None

opts, args = getopt.getopt(sys.argv[1:], "e:p:l:")
for opt, arg in opts:
    print opt, arg
    if opt in "-e":
        env = arg
    if opt in "-p":
        password = arg
    if opt in "-l":
        list = arg

print "env", env
print "password", password
print "list", list

java weblogic.WLST -e pippo -l cino,cano

the output is:

-e pippo
-l cino,cano
env pippo
password None
list cino,cano

Later, you can check if an argument has been passed by

if password is None:
    print "missing argument password"        

No comments: