From 0e17445ff0cfb5970a3496f9d39f179d459314a3 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 7 Nov 2012 19:58:43 +0100 Subject: [PATCH] pattern matching dev --- action_map.yml | 1 + parse_args | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/action_map.yml b/action_map.yml index 237204ae..27b3467a 100644 --- a/action_map.yml +++ b/action_map.yml @@ -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 diff --git a/parse_args b/parse_args index ad6020f7..ca749278 100755 --- a/parse_args +++ b/parse_args @@ -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,9 +91,23 @@ def parse_dict(action_map): if 'full' in arg_params: arg_fullname = arg_params['full'] del arg_params['full'] - parsers[category + '_' + action].add_argument(arg_name, arg_fullname, **arg_params) else: - parsers[category + '_' + action].add_argument(arg_name, **arg_params) + 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) return parsers['general'].parse_args() @@ -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)