update help of "add" command, and improve code

This commit is contained in:
Romain Bignon 2015-04-04 12:38:49 +02:00
commit acb7b4c9e9

View file

@ -93,25 +93,24 @@ class WeboobCfg(ReplApplication):
def do_add(self, line):
"""
add NAME [OPTIONS ...]
add MODULE_NAME [BACKEND_NAME] [PARAMETERS ...]
Add a backend.
Create a backend from a module. By default, if BACKEND_NAME is omitted,
that's the module name which is used.
You can specify parameters from command line in form "key=value".
"""
if not line:
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
return 2
module_name, options = self.parse_command_args(line, 2, 1)
if options:
options = options.split(' ')
else:
options = ()
backend_name = module_name
try:
k, v = options[0].split('=',1)
except ValueError:
backend_name = options[0]
del options[0]
backend_name = None
params = {}
# set backend params from command-line arguments
@ -119,11 +118,15 @@ class WeboobCfg(ReplApplication):
try:
key, value = option.split('=', 1)
except ValueError:
if backend_name is None:
backend_name = option
else:
print('Parameters have to be formatted "key=value"', file=self.stderr)
return 2
else:
params[key] = value
self.add_backend(module_name, backend_name, params)
self.add_backend(module_name, backend_name or module_name, params)
def do_register(self, line):
"""