diff options
| author | Marq Schneider <queueRAM@gmail.com> | 2010-07-22 22:57:40 -0500 |
|---|---|---|
| committer | Marq Schneider <queueRAM@gmail.com> | 2010-07-22 22:57:40 -0500 |
| commit | fd18baa9e62f6defd4a285425bd087a4b27c82d3 (patch) | |
| tree | 8d60638aa637f0ac5412a011fe13f7e9f6c343ac /cli/start.c | |
| parent | b1d891c7b134755e60175a6c1cdf25f0e618d159 (diff) | |
| download | btpd-fd18baa9e62f6defd4a285425bd087a4b27c82d3.tar.gz btpd-fd18baa9e62f6defd4a285425bd087a4b27c82d3.zip | |
Implement start all (btcli start -a) functionality.
Closes GH-7
Diffstat (limited to 'cli/start.c')
| -rw-r--r-- | cli/start.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/cli/start.c b/cli/start.c index e3a3684..2bd55ad 100644 --- a/cli/start.c +++ b/cli/start.c @@ -12,6 +12,10 @@ usage_start(void) "torrent ...\n" "\tThe torrents to activate.\n" "\n" + "Options:\n" + "-a\n" + "\tActivate all inactive torrents.\n" + "\n" ); exit(1); } @@ -24,19 +28,32 @@ static struct option start_opts [] = { void cmd_start(int argc, char **argv) { - int ch; + int ch, all = 0; struct ipc_torrent t; - while ((ch = getopt_long(argc, argv, "", start_opts, NULL)) != -1) - usage_start(); + while ((ch = getopt_long(argc, argv, "a", start_opts, NULL)) != -1) { + switch (ch) { + case 'a': + all = 1; + break; + default: + usage_start(); + } + } argc -= optind; argv += optind; - if (argc < 1) + if ((argc == 0 && !all) || (all && argc != 0)) usage_start(); btpd_connect(); - for (int i = 0; i < argc; i++) - if (torrent_spec(argv[i], &t)) - handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]); + if (all) { + enum ipc_err code = btpd_start_all(ipc); + if (code != IPC_OK) + diemsg("command failed (%s).\n", ipc_strerror(code)); + } else { + for (int i = 0; i < argc; i++) + if (torrent_spec(argv[i], &t)) + handle_ipc_res(btpd_start(ipc, &t), "start", argv[i]); + } } |