update help of "add" command, and improve code
This commit is contained in:
parent
7155539965
commit
acb7b4c9e9
1 changed files with 15 additions and 12 deletions
|
|
@ -93,25 +93,24 @@ class WeboobCfg(ReplApplication):
|
||||||
|
|
||||||
def do_add(self, line):
|
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:
|
if not line:
|
||||||
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
|
print('You must specify a module name. Hint: use the "modules" command.', file=self.stderr)
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
module_name, options = self.parse_command_args(line, 2, 1)
|
module_name, options = self.parse_command_args(line, 2, 1)
|
||||||
if options:
|
if options:
|
||||||
options = options.split(' ')
|
options = options.split(' ')
|
||||||
else:
|
else:
|
||||||
options = ()
|
options = ()
|
||||||
|
|
||||||
backend_name = module_name
|
backend_name = None
|
||||||
try:
|
|
||||||
k, v = options[0].split('=',1)
|
|
||||||
except ValueError:
|
|
||||||
backend_name = options[0]
|
|
||||||
del options[0]
|
|
||||||
|
|
||||||
params = {}
|
params = {}
|
||||||
# set backend params from command-line arguments
|
# set backend params from command-line arguments
|
||||||
|
|
@ -119,11 +118,15 @@ class WeboobCfg(ReplApplication):
|
||||||
try:
|
try:
|
||||||
key, value = option.split('=', 1)
|
key, value = option.split('=', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('Parameters have to be formatted "key=value"', file=self.stderr)
|
if backend_name is None:
|
||||||
return 2
|
backend_name = option
|
||||||
params[key] = value
|
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):
|
def do_register(self, line):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue