[core] Allow mixing of parameter specs

Allow modules and parameters to be specified as either simple lists (-p
a b c d) or as multiple instances (-p a -p b -p c).

fixes #362
This commit is contained in:
Tobias Witek 2019-02-15 18:01:06 +01:00
parent 193305dc11
commit 930c70e06a

View file

@ -48,10 +48,10 @@ class print_usage(argparse.Action):
def create_parser(): def create_parser():
"""Create the argument parser""" """Create the argument parser"""
parser = argparse.ArgumentParser(description="display system data in the i3bar") parser = argparse.ArgumentParser(description="display system data in the i3bar")
parser.add_argument("-m", "--modules", nargs="+", default=[], parser.add_argument("-m", "--modules", nargs="+", action='append', default=[],
help=MODULE_HELP) help=MODULE_HELP)
parser.add_argument("-t", "--theme", default="default", help=THEME_HELP) parser.add_argument("-t", "--theme", default="default", help=THEME_HELP)
parser.add_argument("-p", "--parameters", nargs="+", default=[], parser.add_argument("-p", "--parameters", nargs="+", action='append', default=[],
help=PARAMETER_HELP) help=PARAMETER_HELP)
parser.add_argument("-l", "--list", choices=["modules", "themes"], action=print_usage, parser.add_argument("-l", "--list", choices=["modules", "themes"], action=print_usage,
help=LIST_HELP) help=LIST_HELP)
@ -82,16 +82,18 @@ class Config(bumblebee.store.Store):
if not self._args.debug: if not self._args.debug:
logging.getLogger().disabled = True logging.getLogger().disabled = True
for param in self._args.parameters: parameters = [item for sub in self._args.parameters for item in sub]
for param in parameters:
key, value = param.split("=") key, value = param.split("=")
self.set(key, value) self.set(key, value)
def modules(self): def modules(self):
modules = [item for sub in self._args.modules for item in sub]
"""Return a list of all activated modules""" """Return a list of all activated modules"""
return [{ return [{
"module": x.split(":")[0], "module": x.split(":")[0],
"name": x if not ":" in x else x.split(":")[1], "name": x if not ":" in x else x.split(":")[1],
} for x in self._args.modules] } for x in modules]
def theme(self): def theme(self):
"""Return the name of the selected theme""" """Return the name of the selected theme"""