about summary refs log tree commit diff
path: root/cli/del.c
blob: dbbf3c67fd53a6498abefb8303a97b5ba7120728 (plain)
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
#include "btcli.h"

void
usage_del(void)
{
    printf(
        "Remove torrents from btpd.\n"
        "\n"
        "Usage: del torrent ...\n"
        "\n"
        "Arguments:\n"
        "torrent ...\n"
        "\tThe torrents to remove.\n"
        "\n");
    exit(1);
}

static struct option del_opts [] = {
    { "help", no_argument, NULL, 'H' },
    {NULL, 0, NULL, 0}
};

void
cmd_del(int argc, char **argv)
{
    int ch;
    struct ipc_torrent t;

    while ((ch = getopt_long(argc, argv, "", del_opts, NULL)) != -1)
        usage_del();
    argc -= optind;
    argv += optind;

    if (argc < 1)
        usage_del();

    btpd_connect();
    for (int i = 0; i < argc; i++)
        if (torrent_spec(argv[i], &t))
            handle_ipc_res(btpd_del(ipc, &t), "del", argv[i]);
}