File size: 1,639 Bytes
3d3d712
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from dataclasses import dataclass
from functools import wraps
from textwrap import dedent
from typing import Any, Callable, Optional

import click


def require_workspace():
    def require_workspace_inner(f: Callable[..., None]):
        @wraps(f)
        @click.pass_context
        def new_func(ctx: click.Context, *args: Any, **kwargs: Any):
            if ctx.obj.is_workspace_valid:
                return ctx.invoke(f, *args, **kwargs)
            else:
                click.echo(
                    "The current directory is not a valid Task Weaver project directory. "
                    "There needs to be a `taskweaver-config.json` in the root of the project directory. "
                    "Please change the working directory to a valid project directory or initialize a new one. "
                    "Refer to --help for more information.",
                )
                ctx.exit(1)

        return new_func

    return require_workspace_inner


@dataclass
class CliContext:
    workspace: Optional[str]
    workspace_param: Optional[str]
    is_workspace_valid: bool
    is_workspace_empty: bool


def get_ascii_banner() -> str:
    return dedent(
        r"""
        =========================================================
         _____         _     _       __
        |_   _|_ _ ___| | _ | |     / /__  ____ __   _____  _____
          | |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/
          | | (_| \__ \   < | |/ |/ /  __/ /_/ /| |/ /  __/ /
          |_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/
        =========================================================
        """,
    ).strip()