~mapperr/trl

7f79036032043c701c80f787d098a9b90af8f87a — mapperr 2 years ago 3af86c0
Better list management
2 files changed, 22 insertions(+), 11 deletions(-)

M trullo.py
M trullo/printer.py
M trullo.py => trullo.py +4 -4
@@ 2,7 2,7 @@

usage:
    trl b [<board_shortcut>]
    trl l [<list_shortcut>]
    trl l [<list_shortcuts>...]
    trl ll
    trl c <card_shortcut> [o | m <list_shortcut> | e | n <list_shortcut>]
    trl c n <list_shortcut>


@@ 143,9 143,9 @@ if __name__ == '__main__':

    if args['l']:
        board = tclient.get_board(selected_board_id)
        list_shortcut = args['<list_shortcut>']
        if list_shortcut:
            Printer.print_board(board, list_shortcut)
        list_shortcuts = args['<list_shortcuts>']
        if list_shortcuts is not None and len(list_shortcuts) > 0:
            Printer.print_board(board, list_shortcuts)
        else:
            Printer.print_board(board)


M trullo/printer.py => trullo/printer.py +18 -7
@@ 1,4 1,4 @@
from typing import List
from typing import List, Optional

import attr



@@ 21,7 21,15 @@ class Printer:
                f"{board.raw_data['name']}")

    @staticmethod
    def print_board(board: TrlBoard, list_shortcut: str = None):
    def there_is_a_match(normalized_name: str, shortcuts: List[str]) -> bool:
        return len([
            shortcut for shortcut in shortcuts
            if normalized_name.startswith(shortcut)
        ]) > 0

    @staticmethod
    def print_board(board: TrlBoard,
                    list_shortcuts: Optional[List[str]] = None):
        cards_names = [card.get_normalized_name() for card in board.cards]
        board_lists_names = \
            [list_.get_normalized_name() for list_ in board.lists]


@@ 35,11 43,14 @@ class Printer:
        print(f"{board.raw_data['name']}")
        print()
        if board.lists is not None:
            for list_ in board.lists:
                if list_shortcut is not None \
                        and not \
                        list_.get_normalized_name().startswith(list_shortcut):
                    continue
            matching_lists = board.lists
            if list_shortcuts is not None and len(list_shortcuts) > 0:
                matching_lists = [
                    list_ for list_ in board.lists
                    if Printer.there_is_a_match(list_.get_normalized_name(),
                                                list_shortcuts)
                ]
            for list_ in matching_lists:
                shortcut = \
                    list_.get_normalized_name()[0:symbol_count_lists].lower()
                print(f"[{shortcut}] {list_.raw_data['name']}")