Exemple #1
0
def grep(ctx, pattern, insensitive, count, regexp, by, fields, use_json):
    '''egrep through titles of cards on this board. This command attemps to replicate a couple of grep flags
    faithfully, so if you're a power-user of grep this command will feel familiar.
    One deviation from grep is the --json flag, which outputs all matching cards in full JSON format.
    '''
    if not (pattern or regexp):
        click.secho(
            'No pattern provided to grep: use either the argument or -e',
            fg='red')
        raise GTDException(1)
    # Merge together the different regex arguments
    final_pattern = '|'.join(regexp) if regexp else ''
    if pattern and final_pattern:
        final_pattern = final_pattern + '|' + pattern
    elif pattern:
        final_pattern = pattern
    flags = re.I if insensitive else 0
    cards = CardView.create(ctx,
                            status='visible',
                            title_regex=final_pattern,
                            regex_flags=flags)
    if count:
        print(sum(1 for _ in cards))
        return
    if use_json:
        print(cards.json())
    else:
        ctx.display.banner()
        ctx.display.show_cards(cards, sort=by, table_fields=fields)
Exemple #2
0
def delete_cards(ctx, force, noninteractive, tags, no_tags, match, listname,
                 attachments, has_due, status):
    '''Delete a set of cards specified
    '''
    ctx.display.banner()
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    method = 'delete' if force else 'archive'
    if noninteractive:
        if force:
            [c.delete() for c in cards]
        else:
            [c.set_closed(True) for c in cards]
    else:
        for card in cards:
            ctx.display.show_card(card)
            if prompt_for_confirmation('Delete this card?'):
                if force:
                    card.delete()
                else:
                    card.set_closed(True)
                click.secho(f'Card {method}d!', fg='red')
Exemple #3
0
def show_soon(ctx, use_json, tsv):
    cards = CardView.create(ctx, status='visible', has_due_date=True)
    if use_json:
        print(cards.json())
    else:
        ctx.display.banner()
        ctx.display.show_cards(cards, tsv=tsv, sort='due')
Exemple #4
0
def batch_attach(ctx):
    '''Extract HTTP links from card titles'''
    cards = CardView.create(ctx, status='visible', title_regex=VALID_URL_REGEX)
    ctx.display.banner()
    for card in cards:
        ctx.display.show_card(card)
        if prompt_for_confirmation('Attach title?', True):
            card.title_to_link()
Exemple #5
0
def batch_tag(ctx, tags, no_tags, match, listname, attachments, has_due,
              status):
    '''Change tags on each card selected'''
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    ctx.display.banner()
    for card in cards:
        ctx.display.show_card(card)
        card.add_labels(ctx._label_choices)
Exemple #6
0
def batch_due(ctx, tags, no_tags, match, listname, attachments, has_due,
              status):
    '''Set due date for all cards selected'''
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    ctx.display.banner()
    for card in cards:
        ctx.display.show_card(card)
        if prompt_for_confirmation('Set due date?'):
            card.set_due_date()
Exemple #7
0
def batch_move(ctx, tags, no_tags, match, listname, attachments, has_due,
               status):
    '''Change the list of each card selected'''
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    ctx.display.banner()
    for card in cards:
        ctx.display.show_card(card)
        if prompt_for_confirmation('Want to move this one?', True):
            card.move_to_list(ctx._list_choices)
Exemple #8
0
def review(ctx, tags, no_tags, match, listname, attachments, has_due, status):
    '''show a smart, command-line based menu for each card selected.
    This menu will prompt you to add tags to untagged cards, to attach the title
    of cards which have a link in the title, and gives you all the other functionality combined.
    '''
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    ctx.display.banner()
    card = cards.current()
    while card is not None:
        if ctx.card_repl(card):
            card = cards.next()
        else:
            card = cards.prev()
Exemple #9
0
def show_cards(ctx, use_json, tsv, tags, no_tags, match, listname, attachments,
               has_due, status, by, fields):
    '''Display cards
    The show command prints a table of all the cards with fields that will fit on the terminal you're using.
    You can change this formatting by passing one of --tsv or --json, which will output as a tab-separated value sheet
    or JSON. This command along with the batch & review commands share a flexible argument scheme for getting card
    information. Mutually exclusive arguments include -t/--tags & --no-tags along with -j/--json & --tsv
    '''
    cards = CardView.create(
        ctx,
        status=status,
        tags=tags,
        no_tags=no_tags,
        title_regex=match,
        list_regex=listname,
        has_attachments=attachments,
        has_due_date=has_due,
    )
    if use_json:
        print(cards.json())
    else:
        ctx.display.banner()
        ctx.display.show_cards(cards, tsv=tsv, sort=by, table_fields=fields)