## ecr.commands.helper

src/ecr/commands/helper.py
    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
    from typing import Tuple, cast

    from .. import shared, ui
    from ..core import WorkItem, WorkManager
    from ..ui import color
    from ..ui.command import Namespace

    def printFileModify(file: str) -> None:
        console = ui.getConsole()
        console.write(color.useYellow("M"), file)

    def printFileCreate(file: str) -> None:
        console = ui.getConsole()
        console.write(color.useGreen("+"), file)

    def printFileDelete(file: str) -> None:
        console = ui.getConsole()
        console.write(color.useRed("-"), file)

    def assertInited() -> bool:
        console = ui.getConsole()
        if not shared.getManager():
            console.error("Not have any ecr directory")
            return False
        return True

    def getItem(tman: WorkManager, args: Namespace)->Tuple[WorkItem, str]:
        if args.file:
            item = tman.getWorkItem(
                args.file, args.dir)
        else:
            item = cast(WorkItem, tman.currentFile)
        assert item
        file = item.name
        return item, file