summaryrefslogtreecommitdiffstats
path: root/src/lib/Options.py
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2008-03-08 18:42:00 +0000
committerNarayan Desai <desai@mcs.anl.gov>2008-03-08 18:42:00 +0000
commit64bb16f5f70c6cc97cede6782e45583af9bdced3 (patch)
tree7feb0f331fc026e23e307519afd7c3661efc04ed /src/lib/Options.py
parent07467bbc04b77453a9d27a5dd82729d304eddb70 (diff)
downloadbcfg2-64bb16f5f70c6cc97cede6782e45583af9bdced3.tar.gz
bcfg2-64bb16f5f70c6cc97cede6782e45583af9bdced3.tar.bz2
bcfg2-64bb16f5f70c6cc97cede6782e45583af9bdced3.zip
implement support for long options
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@4404 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Options.py')
-rw-r--r--src/lib/Options.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/src/lib/Options.py b/src/lib/Options.py
index b25fb59fb..7d0ed557c 100644
--- a/src/lib/Options.py
+++ b/src/lib/Options.py
@@ -32,12 +32,17 @@ class Option(object):
value = property(getValue)
def __init__(self, desc, default, cmd=False, odesc=False,
- env=False, cf=False, cook=False):
+ env=False, cf=False, cook=False, long_arg=False):
self.desc = desc
self.default = default
self.cmd = cmd
- if cmd and (cmd[0] != '-' or len(cmd) != 2):
- raise OptionFailure("Poorly formed command %s" % cmd)
+ self.long = long_arg
+ if not self.long:
+ if cmd and (cmd[0] != '-' or len(cmd) != 2):
+ raise OptionFailure("Poorly formed command %s" % cmd)
+ else:
+ if cmd and (not cmd.startswith('--')):
+ raise OptionFailure("Poorly formed command %s" % cmd)
self.odesc = odesc
self.env = env
self.cf = cf
@@ -59,12 +64,20 @@ class Option(object):
def buildGetopt(self):
gstr = ''
+ if self.long:
+ return gstr
if self.cmd:
gstr = self.cmd[1]
if self.odesc:
gstr += ':'
return gstr
+ def buildLongGetopt(self):
+ if self.odesc:
+ return self.cmd[2:]+'='
+ else:
+ return self.cmd[2:]
+
def parse(self, opts, rawopts):
if self.cmd and opts:
# processing getopted data
@@ -94,6 +107,9 @@ class OptionSet(dict):
def buildGetopt(self):
return ''.join([opt.buildGetopt() for opt in self.values()])
+ def buildLongGetopt(self):
+ return [opt.buildLongGetopt() for opt in self.values() if opt.long]
+
def buildHelpMessage(self):
return ''.join([opt.buildHelpMessage() for opt in self.values()])
@@ -109,7 +125,8 @@ class OptionSet(dict):
ret = {}
if do_getopt:
try:
- opts, args = getopt.getopt(argv, self.buildGetopt(), [])
+ opts, args = getopt.getopt(argv, self.buildGetopt(),
+ self.buildLongGetopt())
except getopt.GetoptError, err:
self.helpExit(err)
if '-h' in argv: