pattern matching dev

This commit is contained in:
root 2012-11-07 19:58:43 +01:00
parent 72dd190f39
commit 0e17445ff0
2 changed files with 18 additions and 4 deletions

View file

@ -58,6 +58,7 @@ user:
-f:
full: --filter
help: LDAP filter used to search
pattern: 'yayaya'
-l:
full: --limit
help: Maximum number of user fetched

View file

@ -38,7 +38,7 @@ if not __debug__:
gettext.install('YunoHost')
try:
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, connect_services, disconnect_services
from yunohost import YunoHostError, YunoHostLDAP, str_to_func, colorize, pretty_print_dict, display_error, connect_services, disconnect_services, validate
except ImportError:
sys.stderr.write('Error: Yunohost CLI Require YunoHost lib\n')
sys.exit(1)
@ -91,6 +91,20 @@ def parse_dict(action_map):
if 'full' in arg_params:
arg_fullname = arg_params['full']
del arg_params['full']
else:
arg_fullname = False
if 'pattern' in arg_params:
pattern = arg_params['pattern']
del arg_params['pattern']
def pmatch(string):
validate({ string : pattern })
if arg_fullname:
parsers[category + '_' + action].add_argument(arg_name, arg_fullname, type=pmatch, **arg_params)
else:
parsers[category + '_' + action].add_argument(arg_name, type=pmatch, **arg_params)
else:
if arg_fullname:
parsers[category + '_' + action].add_argument(arg_name, arg_fullname, **arg_params)
else:
parsers[category + '_' + action].add_argument(arg_name, **arg_params)
@ -114,7 +128,6 @@ def main():
args = parse_dict(action_map)
connections = connect_services(action_map)
try:
if connections:
result = args.func(vars(args), connections)