Esempio n. 1
0
        def _completer(ctx, args, incomplete):
            store = self._get_store(loaded=True)
            res = [(ZSH_COMPLETION_SUFFIX, "")]

            if with_root and len(ctx.args) > 0:
                params = store.search(
                    indices_names=[PARAM_FAMILY, PARAM_FULL],
                    prefix=ctx.args[0] + "." + incomplete,
                )

                for param_name, param_desc in params.items():
                    _, param_name = param_name.rsplit(".", maxsplit=1)
                    short_desc = _help(param_desc)
                    res.append((param_name, short_desc))

            if not with_tasks:
                return res

            task_name = incomplete
            if "." in incomplete:
                task_name, _ = incomplete.rsplit(".", maxsplit=1)

            tasks = store.search(indices, task_name)

            if task_name in tasks:
                params = store.search(
                    indices_names=[PARAM_FAMILY, PARAM_FULL], prefix=incomplete
                )

                for key, param_desc in params.items():
                    short_desc = _help(param_desc)
                    res.append((key, short_desc))

                return res

            for task_name, task_desc in tasks.items():
                short_desc = _help_short(task_desc)
                res.append((task_name + ".", short_desc))

            return res
Esempio n. 2
0
        def _completer(ctx, args, incomplete):
            store = self._get_store(loaded=True)
            tasks = store.search(indices, incomplete)

            if incomplete in tasks:
                return []

            res = []
            for task_name, task_desc in tasks.items():
                short_desc = _help(task_desc)
                res.append((task_name, short_desc))

            return res
Esempio n. 3
0
def print_help(ctx, task_cls):
    from dbnd._core.parameter.parameter_definition import _ParameterKind

    formatter = ctx.make_formatter()
    run.format_help(ctx, formatter)
    if task_cls:
        dl = []
        for (param_name, param_obj) in task_cls.task_definition.task_params.items():
            if param_obj.system or param_obj.kind == _ParameterKind.task_output:
                continue

            param_help = _help(param_obj.description)
            dl.append(("-r " + param_name, param_help))

        with formatter.section("Task"):
            formatter.write_dl(dl)
    click.echo(formatter.getvalue().rstrip("\n"), color=ctx.color)
Esempio n. 4
0
def _list_tasks(ctx, module, search, is_config):
    from dbnd import Config
    from dbnd._core.context.databand_context import new_dbnd_context
    from dbnd._core.parameter.parameter_definition import _ParameterKind

    formatter = ctx.make_formatter()

    load_user_modules(config, modules=module)

    with new_dbnd_context():
        tasks = get_task_registry().list_dbnd_task_classes()

    for task_cls in tasks:
        td = task_cls.task_definition
        full_task_family = td.full_task_family
        task_family = td.task_family

        if not (task_family.startswith(search) or full_task_family.startswith(search)):
            continue

        if issubclass(task_cls, Config) != is_config:
            continue

        dl = []
        for param_name, param_obj in td.task_param_defs.items():
            if param_obj.system or param_obj.kind == _ParameterKind.task_output:
                continue
            if not is_config and param_name in COMMON_PARAMS:
                continue
            param_help = _help(param_obj.description)
            dl.append((param_name, param_help))

        if dl:
            with formatter.section(
                "{task_family} ({full_task_family})".format(
                    full_task_family=full_task_family, task_family=task_family
                )
            ):
                formatter.write_dl(dl)

    click.echo(formatter.getvalue().rstrip("\n"))