Revision 24ff0a35 kamaki/cli/__init__.py

b/kamaki/cli/__init__.py
53 53
_best_match = []
54 54

  
55 55

  
56
def _arg2syntax(arg):
57
    return arg.replace(
58
        '____', '[:').replace(
59
        '___', ':').replace(
60
        '__', ']').replace(
61
        '_', ' ')
62

  
63

  
56 64
def _construct_command_syntax(cls):
57 65
        spec = getargspec(cls.main.im_func)
58 66
        args = spec.args[1:]
59 67
        n = len(args) - len(spec.defaults or ())
60
        required = ' '.join(
61
            '<%s>' % x.replace(
62
            '____', '[:').replace(
63
            '___', ':').replace(
64
            '__', ']').replace(
65
            '_', ' ') for x in args[:n])
66
        optional = ' '.join(
67
            '[%s]' % x.replace(
68
            '____', '[:').replace(
69
            '___', ':').replace(
70
            '__', ']').replace(
71
            '_', ' ') for x in args[n:])
68
        required = ' '.join(['<%s>' % _arg2syntax(x) for x in args[:n]])
69
        optional = ' '.join(['[%s]' % _arg2syntax(x) for x in args[n:]])
72 70
        cls.syntax = ' '.join(x for x in [required, optional] if x)
73 71
        if spec.varargs:
74 72
            cls.syntax += ' <%s ...>' % spec.varargs
......
242 240
        if pkg:
243 241
            cmds = None
244 242
            try:
245
                cmds = [
246
                    cmd for cmd in getattr(pkg, '_commands')
247
                        if arguments['config'].get(cmd.name, 'cli')
248
                ]
243
                _cnf = arguments['config']
244
                cmds = [cmd for cmd in getattr(pkg, '_commands') if _cnf.get(
245
                    cmd.name, 'cli')]
249 246
            except AttributeError:
250 247
                if _debug:
251 248
                    kloger.warning('No description for %s' % spec)
......
262 259

  
263 260

  
264 261
def _load_all_commands(cmd_tree, arguments):
265
    _config = arguments['config']
266
    for spec in [spec for spec in _config.get_groups()
267
        if _config.get(spec, 'cli')]:
262
    _cnf = arguments['config']
263
    specs = [spec for spec in _cnf.get_groups() if _cnf.get(spec, 'cli')]
264
    for spec in specs:
268 265
        try:
269 266
            spec_module = _load_spec_module(spec, arguments, '_commands')
270 267
            spec_commands = getattr(spec_module, '_commands')

Also available in: Unified diff