<commit_before>import click

from globus_cli.safeio import safeprint
from globus_cli.parsing import common_options, task_id_option
from globus_cli.helpers import outformat_is_json, print_json_response

from globus_cli.services.transfer.helpers import get_client


@click.command('cancel', short_help='Cancel a Task',
               help='Cancel a Task owned by the current user')
@common_options
@task_id_option(helptext='ID of the Task which you want to cancel')
def cancel_task(task_id):
    """
    Executor for `globus transfer task cancel`
    """
    client = get_client()

    res = client.cancel_task(task_id)

    if outformat_is_json():
        print_json_response(res)
    else:
        safeprint(res['message'])<commit_msg>Support for globus task cancel --all<commit_after>import json
import click

from globus_cli.safeio import safeprint
from globus_cli.parsing import common_options, task_id_option
from globus_cli.helpers import outformat_is_json, print_json_response

from globus_cli.services.transfer.helpers import get_client


@click.command('cancel', short_help='Cancel a Task',
               help='Cancel a Task owned by the current user')
@common_options
@task_id_option(helptext='ID of the Task which you want to cancel',
                required=False)
@click.option('--all', '-a', is_flag=True,
              help='Cancel all in-progress tasks that you own')
def cancel_task(all, task_id):
    """
    Executor for `globus transfer task cancel`
    """

    if bool(all) + bool(task_id) != 1:
        raise click.UsageError('You must pass EITHER the special --all flag '
                               'to cancel all in-progress tasks OR a single '
                               'task ID to cancel.')

    client = get_client()

    if all:
        from sys import maxsize
        task_ids = [
            task_row['task_id']
            for task_row in client.task_list(
                filter='type:TRANSFER,DELETE/status:ACTIVE,INACTIVE',
                fields='task_id',
                num_results=maxsize,  # FIXME want to ask for "unlimited" set
            )
        ]

        if not task_ids:
            raise click.ClickException('You have no in-progress tasks.')

        if outformat_is_json():
            safeprint(json.dumps([client.cancel_task(task_id).data
                                  for task_id in task_ids], indent=2))

        else:
            task_count = len(task_ids)
            safeprint('Canceling all tasks ({} total)...'.format(task_count))
            for task_number, task_id in enumerate(task_ids, start=1):
                safeprint('{} ({} of {}): {}'.
                          format(task_id, task_number, task_count,
                                 client.cancel_task(task_id)['message']))

    else:
        res = client.cancel_task(task_id)

        if outformat_is_json():
            print_json_response(res)
        else:
            safeprint(res['message'])
{'fraction_non_alphanumeric': 0.0935692412385165, 'fraction_numerical': 0.0010207553589656345, 'mean_word_length': 2.442622950819672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4658783', 'n_tokens_mistral': 860, 'n_tokens_neox': 833, 'n_words': 220}