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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
|
/*
* This file is part of nzbget. See <http://nzbget.net>.
*
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nzbget.h"
#include "CommandLineParser.h"
#include "Log.h"
#include "MessageBase.h"
#include "DownloadInfo.h"
#include "FileSystem.h"
#include "Util.h"
#ifdef HAVE_GETOPT_LONG
static struct option long_options[] =
{
{"help", no_argument, 0, 'h'},
{"configfile", required_argument, 0, 'c'},
{"noconfigfile", no_argument, 0, 'n'},
{"printconfig", no_argument, 0, 'p'},
{"server", no_argument, 0, 's' },
{"daemon", no_argument, 0, 'D' },
{"version", no_argument, 0, 'v'},
{"serverversion", no_argument, 0, 'V'},
{"option", required_argument, 0, 'o'},
{"append", no_argument, 0, 'A'},
{"list", no_argument, 0, 'L'},
{"pause", no_argument, 0, 'P'},
{"unpause", no_argument, 0, 'U'},
{"rate", required_argument, 0, 'R'},
{"system", no_argument, 0, 'B'},
{"log", required_argument, 0, 'G'},
{"top", no_argument, 0, 'T'},
{"edit", required_argument, 0, 'E'},
{"connect", no_argument, 0, 'C'},
{"quit", no_argument, 0, 'Q'},
{"reload", no_argument, 0, 'O'},
{"write", required_argument, 0, 'W'},
{"category", required_argument, 0, 'K'},
{"scan", no_argument, 0, 'S'},
{0, 0, 0, 0}
};
#endif
static char short_options[] = "c:hno:psvAB:DCE:G:K:LPR:STUQOVW:";
CommandLineParser::CommandLineParser(int argc, const char* argv[])
{
InitCommandLine(argc, argv);
if (argc == 1)
{
m_printUsage = true;
return;
}
if (!m_printOptions && !m_printUsage && !m_printVersion)
{
InitFileArg(argc, argv);
}
}
void CommandLineParser::InitCommandLine(int argc, const char* const_argv[])
{
m_clientOperation = opClientNoOperation; // default
std::vector<CString> argv;
argv.reserve(argc);
for (int i = 0; i < argc; i++)
{
argv.emplace_back(const_argv[i]);
}
// reset getopt
optind = 0;
while (true)
{
int c;
#ifdef HAVE_GETOPT_LONG
int option_index = 0;
c = getopt_long(argc, (char**)argv.data(), short_options, long_options, &option_index);
#else
c = getopt(argc, (char**)argv.data(), short_options);
#endif
if (c == -1) break;
switch (c)
{
case 'c':
m_configFilename = optarg;
break;
case 'n':
m_configFilename = nullptr;
m_noConfig = true;
break;
case 'h':
m_printUsage = true;
return;
case 'v':
m_printVersion = true;
return;
case 'p':
m_printOptions = true;
break;
case 'o':
m_optionList.push_back(optarg);
break;
case 's':
m_serverMode = true;
break;
case 'D':
m_serverMode = true;
m_daemonMode = true;
break;
case 'A':
m_clientOperation = opClientRequestDownload;
while (true)
{
optind++;
optarg = optind > argc ? nullptr : (char*)argv[optind-1];
if (optarg && (!strcasecmp(optarg, "F") || !strcasecmp(optarg, "U")))
{
// option ignored (but kept for compatibility)
}
else if (optarg && !strcasecmp(optarg, "T"))
{
m_addTop = true;
}
else if (optarg && !strcasecmp(optarg, "P"))
{
m_addPaused = true;
}
else if (optarg && !strcasecmp(optarg, "I"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
m_addPriority = atoi(argv[optind-1]);
}
else if (optarg && !strcasecmp(optarg, "C"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
m_addCategory = std::move(argv[optind-1]);
}
else if (optarg && !strcasecmp(optarg, "N"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
m_addNzbFilename = std::move(argv[optind-1]);
}
else if (optarg && !strcasecmp(optarg, "DK"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
m_addDupeKey = std::move(argv[optind-1]);
}
else if (optarg && !strcasecmp(optarg, "DS"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
m_addDupeScore = atoi(argv[optind-1]);
}
else if (optarg && !strcasecmp(optarg, "DM"))
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'A'");
return;
}
const char* dupeMode = argv[optind-1];
if (!strcasecmp(dupeMode, "score"))
{
m_addDupeMode = dmScore;
}
else if (!strcasecmp(dupeMode, "all"))
{
m_addDupeMode = dmAll;
}
else if (!strcasecmp(dupeMode, "force"))
{
m_addDupeMode = dmForce;
}
else
{
ReportError("Could not parse value of option 'A'");
return;
}
}
else
{
optind--;
break;
}
}
break;
case 'L':
optind++;
optarg = optind > argc ? nullptr : (char*)argv[optind-1];
if (!optarg || !strncmp(optarg, "-", 1))
{
m_clientOperation = opClientRequestListFiles;
optind--;
}
else if (!strcasecmp(optarg, "F") || !strcasecmp(optarg, "FR"))
{
m_clientOperation = opClientRequestListFiles;
}
else if (!strcasecmp(optarg, "G") || !strcasecmp(optarg, "GR"))
{
m_clientOperation = opClientRequestListGroups;
}
else if (!strcasecmp(optarg, "O"))
{
m_clientOperation = opClientRequestPostQueue;
}
else if (!strcasecmp(optarg, "S"))
{
m_clientOperation = opClientRequestListStatus;
}
else if (!strcasecmp(optarg, "H"))
{
m_clientOperation = opClientRequestHistory;
}
else if (!strcasecmp(optarg, "HA"))
{
m_clientOperation = opClientRequestHistoryAll;
}
else
{
ReportError("Could not parse value of option 'L'");
return;
}
if (optarg && (!strcasecmp(optarg, "FR") || !strcasecmp(optarg, "GR")))
{
m_matchMode = mmRegEx;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'L'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
}
break;
case 'P':
case 'U':
optind++;
optarg = optind > argc ? nullptr : (char*)argv[optind-1];
if (!optarg || !strncmp(optarg, "-", 1))
{
m_clientOperation = c == 'P' ? opClientRequestDownloadPause : opClientRequestDownloadUnpause;
optind--;
}
else if (!strcasecmp(optarg, "D"))
{
m_clientOperation = c == 'P' ? opClientRequestDownloadPause : opClientRequestDownloadUnpause;
}
else if (!strcasecmp(optarg, "O"))
{
m_clientOperation = c == 'P' ? opClientRequestPostPause : opClientRequestPostUnpause;
}
else if (!strcasecmp(optarg, "S"))
{
m_clientOperation = c == 'P' ? opClientRequestScanPause : opClientRequestScanUnpause;
}
else
{
ReportError(c == 'P' ? "Could not parse value of option 'P'\n" : "Could not parse value of option 'U'");
return;
}
break;
case 'R':
m_clientOperation = opClientRequestSetRate;
m_setRate = (int)(atof(optarg)*1024);
break;
case 'B':
if (!strcasecmp(optarg, "dump"))
{
m_clientOperation = opClientRequestDumpDebug;
}
else if (!strcasecmp(optarg, "trace"))
{
m_testBacktrace = true;
}
else if (!strcasecmp(optarg, "webget"))
{
m_webGet = true;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'B'");
return;
}
optarg = argv[optind-1];
m_webGetFilename = optarg;
}
else if (!strcasecmp(optarg, "verify"))
{
m_sigVerify = true;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'B'");
return;
}
optarg = argv[optind-1];
m_pubKeyFilename = optarg;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'B'");
return;
}
optarg = argv[optind-1];
m_sigFilename = optarg;
}
else
{
ReportError("Could not parse value of option 'B'");
return;
}
break;
case 'G':
m_clientOperation = opClientRequestLog;
m_logLines = atoi(optarg);
if (m_logLines == 0)
{
ReportError("Could not parse value of option 'G'");
return;
}
break;
case 'T':
m_addTop = true;
break;
case 'C':
m_remoteClientMode = true;
break;
case 'E':
{
m_clientOperation = opClientRequestEditQueue;
bool group = !strcasecmp(optarg, "G") || !strcasecmp(optarg, "GN") || !strcasecmp(optarg, "GR");
bool file = !strcasecmp(optarg, "F") || !strcasecmp(optarg, "FN") || !strcasecmp(optarg, "FR");
if (!strcasecmp(optarg, "GN") || !strcasecmp(optarg, "FN"))
{
m_matchMode = mmName;
}
else if (!strcasecmp(optarg, "GR") || !strcasecmp(optarg, "FR"))
{
m_matchMode = mmRegEx;
}
else
{
m_matchMode = mmId;
};
bool post = !strcasecmp(optarg, "O");
bool history = !strcasecmp(optarg, "H");
if (group || file || post || history)
{
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
optarg = argv[optind-1];
}
if (post)
{
// edit-commands for post-processor-queue
if (!strcasecmp(optarg, "D"))
{
m_editQueueAction = DownloadQueue::eaPostDelete;
}
else
{
ReportError("Could not parse value of option 'E'");
return;
}
}
else if (history)
{
// edit-commands for history
if (!strcasecmp(optarg, "D"))
{
m_editQueueAction = DownloadQueue::eaHistoryDelete;
}
else if (!strcasecmp(optarg, "R"))
{
m_editQueueAction = DownloadQueue::eaHistoryReturn;
}
else if (!strcasecmp(optarg, "P"))
{
m_editQueueAction = DownloadQueue::eaHistoryProcess;
}
else if (!strcasecmp(optarg, "A"))
{
m_editQueueAction = DownloadQueue::eaHistoryRedownload;
}
else if (!strcasecmp(optarg, "F"))
{
m_editQueueAction = DownloadQueue::eaHistoryRetryFailed;
}
else if (!strcasecmp(optarg, "O"))
{
m_editQueueAction = DownloadQueue::eaHistorySetParameter;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
if (!strchr(m_editQueueText, '='))
{
ReportError("Could not parse value of option 'E'");
return;
}
}
else if (!strcasecmp(optarg, "B"))
{
m_editQueueAction = DownloadQueue::eaHistoryMarkBad;
}
else if (!strcasecmp(optarg, "G"))
{
m_editQueueAction = DownloadQueue::eaHistoryMarkGood;
}
else if (!strcasecmp(optarg, "S"))
{
m_editQueueAction = DownloadQueue::eaHistoryMarkSuccess;
}
else
{
ReportError("Could not parse value of option 'E'");
return;
}
}
else
{
// edit-commands for download-queue
if (!strcasecmp(optarg, "T"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupMoveTop : DownloadQueue::eaFileMoveTop;
}
else if (!strcasecmp(optarg, "B"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupMoveBottom : DownloadQueue::eaFileMoveBottom;
}
else if (!strcasecmp(optarg, "P"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupPause : DownloadQueue::eaFilePause;
}
else if (!strcasecmp(optarg, "A"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupPauseAllPars : DownloadQueue::eaFilePauseAllPars;
}
else if (!strcasecmp(optarg, "R"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupPauseExtraPars : DownloadQueue::eaFilePauseExtraPars;
}
else if (!strcasecmp(optarg, "U"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupResume : DownloadQueue::eaFileResume;
}
else if (!strcasecmp(optarg, "D"))
{
m_editQueueAction = group ? DownloadQueue::eaGroupDelete : DownloadQueue::eaFileDelete;
}
else if (!strcasecmp(optarg, "DP"))
{
m_editQueueAction = DownloadQueue::eaGroupParkDelete;
}
else if (!strcasecmp(optarg, "SF"))
{
m_editQueueAction = DownloadQueue::eaGroupSortFiles;
}
else if (!strcasecmp(optarg, "C") || !strcasecmp(optarg, "K") || !strcasecmp(optarg, "CP"))
{
// switch "K" is provided for compatibility with v. 0.8.0 and can be removed in future versions
if (!group)
{
ReportError("Category can be set only for groups");
return;
}
m_editQueueAction = !strcasecmp(optarg, "CP") ? DownloadQueue::eaGroupApplyCategory : DownloadQueue::eaGroupSetCategory;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
}
else if (!strcasecmp(optarg, "N"))
{
if (!group)
{
ReportError("Only groups can be renamed");
return;
}
m_editQueueAction = DownloadQueue::eaGroupSetName;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
}
else if (!strcasecmp(optarg, "M"))
{
if (!group)
{
ReportError("Only groups can be merged");
return;
}
m_editQueueAction = DownloadQueue::eaGroupMerge;
}
else if (!strcasecmp(optarg, "S"))
{
m_editQueueAction = DownloadQueue::eaFileSplit;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
}
else if (!strcasecmp(optarg, "O"))
{
if (!group)
{
ReportError("Post-process parameter can be set only for groups");
return;
}
m_editQueueAction = DownloadQueue::eaGroupSetParameter;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
if (!strchr(m_editQueueText, '='))
{
ReportError("Could not parse value of option 'E'");
return;
}
}
else if (!strcasecmp(optarg, "I"))
{
if (!group)
{
ReportError("Priority can be set only for groups");
return;
}
m_editQueueAction = DownloadQueue::eaGroupSetPriority;
optind++;
if (optind > argc)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueText = std::move(argv[optind-1]);
if (atoi(m_editQueueText) == 0 && strcmp("0", m_editQueueText))
{
ReportError("Could not parse value of option 'E'");
return;
}
}
else
{
m_editQueueOffset = atoi(optarg);
if (m_editQueueOffset == 0)
{
ReportError("Could not parse value of option 'E'");
return;
}
m_editQueueAction = group ? DownloadQueue::eaGroupMoveOffset : DownloadQueue::eaFileMoveOffset;
}
}
break;
}
case 'Q':
m_clientOperation = opClientRequestShutdown;
break;
case 'O':
m_clientOperation = opClientRequestReload;
break;
case 'V':
m_clientOperation = opClientRequestVersion;
break;
case 'W':
m_clientOperation = opClientRequestWriteLog;
if (!strcasecmp(optarg, "I")) {
m_writeLogKind = (int)Message::mkInfo;
}
else if (!strcasecmp(optarg, "W")) {
m_writeLogKind = (int)Message::mkWarning;
}
else if (!strcasecmp(optarg, "E")) {
m_writeLogKind = (int)Message::mkError;
}
else if (!strcasecmp(optarg, "D")) {
m_writeLogKind = (int)Message::mkDetail;
}
else if (!strcasecmp(optarg, "G")) {
m_writeLogKind = (int)Message::mkDebug;
}
else
{
ReportError("Could not parse value of option 'W'");
return;
}
break;
case 'K':
// switch "K" is provided for compatibility with v. 0.8.0 and can be removed in future versions
m_addCategory = optarg;
break;
case 'S':
optind++;
optarg = optind > argc ? nullptr : (char*)argv[optind-1];
if (!optarg || !strncmp(optarg, "-", 1))
{
m_clientOperation = opClientRequestScanAsync;
optind--;
}
else if (!strcasecmp(optarg, "W"))
{
m_clientOperation = opClientRequestScanSync;
}
else
{
ReportError("Could not parse value of option 'S'");
return;
}
break;
case '?':
m_errors = true;
return;
}
}
if (m_serverMode && m_clientOperation == opClientRequestDownloadPause)
{
m_pauseDownload = true;
m_clientOperation = opClientNoOperation;
}
}
void CommandLineParser::PrintUsage(const char* com)
{
printf("Usage:\n"
" %s [switches]\n\n"
"Switches:\n"
" -h, --help Print this help-message\n"
" -v, --version Print version and exit\n"
" -c, --configfile <file> Filename of configuration-file\n"
" -n, --noconfigfile Prevent loading of configuration-file\n"
" (required options must be passed with --option)\n"
" -p, --printconfig Print configuration and exit\n"
" -o, --option <name=value> Set or override option in configuration-file\n"
" -s, --server Start nzbget as a server in console-mode\n"
#ifndef WIN32
" -D, --daemon Start nzbget as a server in daemon-mode\n"
#endif
" -V, --serverversion Print server's version and exit\n"
" -Q, --quit Shutdown server\n"
" -O, --reload Reload config and restart all services\n"
" -A, --append [<options>] <nzb-file/url> Send file/url to server's\n"
" download queue\n"
" <options> are (multiple options must be separated with space):\n"
" T Add file to the top (beginning) of queue\n"
" P Pause added files\n"
" C <name> Assign category to nzb-file\n"
" N <name> Use this name as nzb-filename\n"
" I <priority> Set priority (signed integer)\n"
" DK <dupekey> Set duplicate key (string)\n"
" DS <dupescore> Set duplicate score (signed integer)\n"
" DM (score|all|force) Set duplicate mode\n"
" -C, --connect Attach client to server\n"
" -L, --list [F|FR|G|GR|O|H|S] [RegEx] Request list of items from server\n"
" F List individual files and server status (default)\n"
" FR Like \"F\" but apply regular expression filter\n"
" G List groups (nzb-files) and server status\n"
" GR Like \"G\" but apply regular expression filter\n"
" O List post-processor-queue\n"
" H List history\n"
" HA List history, all records (incl. hidden)\n"
" S Print only server status\n"
" <RegEx> Regular expression (only with options \"FR\", \"GR\")\n"
" using POSIX Extended Regular Expression Syntax\n"
" -P, --pause [D|O|S] Pause server\n"
" D Pause download queue (default)\n"
" O Pause post-processor queue\n"
" S Pause scan of incoming nzb-directory\n"
" -U, --unpause [D|O|S] Unpause server\n"
" D Unpause download queue (default)\n"
" O Unpause post-processor queue\n"
" S Unpause scan of incoming nzb-directory\n"
" -R, --rate <speed> Set download rate on server, in KB/s\n"
" -G, --log <lines> Request last <lines> lines from server's screen-log\n"
" -W, --write <D|I|W|E|G> \"Text\" Send text to server's log\n"
" -S, --scan [W] Scan incoming nzb-directory on server\n"
" W Wait until scan completes (synchronous mode)\n"
" -E, --edit [F|FN|FR|G|GN|GR|O|H] <action> <IDs/Names/RegExs> Edit items\n"
" on server\n"
" F Edit individual files (default)\n"
" FN Like \"F\" but uses names (as \"group/file\")\n"
" instead of IDs\n"
" FR Like \"FN\" but with regular expressions\n"
" G Edit all files in the group (same nzb-file)\n"
" GN Like \"G\" but uses group names instead of IDs\n"
" GR Like \"GN\" but with regular expressions\n"
" O Edit post-processor-queue\n"
" H Edit history\n"
" <action> is one of:\n"
" - for files (F) and groups (G):\n"
" <+offset|-offset> Move in queue relative to current position,\n"
" offset is an integer value\n"
" T Move to top of queue\n"
" B Move to bottom of queue\n"
" D Delete\n"
" P Pause\n"
" U Resume (unpause)\n"
" - for groups (G):\n"
" A Pause all pars\n"
" R Pause extra pars\n"
" DP Delete but keep downloaded files\n"
" I <priority> Set priority (signed integer)\n"
" C <name> Set category\n"
" CP <name> Set category and apply post-process parameters\n"
" N <name> Rename\n"
" M Merge\n"
" SF Sort inner files for optimal order\n"
" S <name> Split - create new group from selected files\n"
" O <name>=<value> Set post-process parameter\n"
" - for post-jobs (O):\n"
" D Delete (cancel post-processing)\n"
" - for history (H):\n"
" D Delete\n"
" P Post-process again\n"
" R Download remaining files\n"
" A Download again\n"
" F Retry download of failed articles\n"
" O <name>=<value> Set post-process parameter\n"
" B Mark as bad\n"
" G Mark as good\n"
" S Mark as success\n"
" <IDs> Comma-separated list of file- or group- ids or\n"
" ranges of file-ids, e. g.: 1-5,3,10-22\n"
" <Names> List of names (with options \"FN\" and \"GN\"),\n"
" e. g.: \"my nzb download%cmyfile.nfo\" \"another nzb\"\n"
" <RegExs> List of regular expressions (options \"FR\", \"GR\")\n"
" using POSIX Extended Regular Expression Syntax\n",
FileSystem::BaseFileName(com),
PATH_SEPARATOR);
}
void CommandLineParser::InitFileArg(int argc, const char* argv[])
{
if (optind >= argc)
{
// no nzb-file passed
if (!m_serverMode && !m_remoteClientMode &&
(m_clientOperation == opClientNoOperation ||
m_clientOperation == opClientRequestDownload ||
m_clientOperation == opClientRequestWriteLog))
{
if (m_clientOperation == opClientRequestWriteLog)
{
ReportError("Log-text not specified");
}
else
{
ReportError("Nzb-file or Url not specified");
}
}
}
else if (m_clientOperation == opClientRequestEditQueue)
{
if (m_matchMode == mmId)
{
ParseFileIdList(argc, argv, optind);
}
else
{
ParseFileNameList(argc, argv, optind);
}
}
else
{
m_lastArg = argv[optind];
// Check if the file-name is a relative path or an absolute path
// If the path starts with '/' its an absolute, else relative
const char* fileName = argv[optind];
#ifdef WIN32
m_argFilename = fileName;
#else
if (fileName[0] == '/' || !strncasecmp(fileName, "http://", 6) || !strncasecmp(fileName, "https://", 7))
{
m_argFilename = fileName;
}
else
{
// TEST
m_argFilename.Reserve(1024 - 1);
getcwd(m_argFilename, 1024);
m_argFilename.AppendFmt("/%s", fileName);
}
#endif
if (m_serverMode || m_remoteClientMode ||
!(m_clientOperation == opClientNoOperation ||
m_clientOperation == opClientRequestDownload ||
m_clientOperation == opClientRequestWriteLog))
{
ReportError("Too many arguments");
}
}
}
void CommandLineParser::ParseFileIdList(int argc, const char* argv[], int optind)
{
m_editQueueIdList.clear();
while (optind < argc)
{
CString writableFileIdList = argv[optind++];
char* optarg = strtok(writableFileIdList, ", ");
while (optarg)
{
int editQueueIdFrom = 0;
int editQueueIdTo = 0;
const char* p = strchr(optarg, '-');
if (p)
{
BString<100> buf;
buf.Set(optarg, (int)(p - optarg));
editQueueIdFrom = atoi(buf);
editQueueIdTo = atoi(p + 1);
if (editQueueIdFrom <= 0 || editQueueIdTo <= 0)
{
ReportError("invalid list of file IDs");
return;
}
}
else
{
editQueueIdFrom = atoi(optarg);
if (editQueueIdFrom <= 0)
{
ReportError("invalid list of file IDs");
return;
}
editQueueIdTo = editQueueIdFrom;
}
int editQueueIdCount = 0;
if (editQueueIdFrom < editQueueIdTo)
{
editQueueIdCount = editQueueIdTo - editQueueIdFrom + 1;
}
else
{
editQueueIdCount = editQueueIdFrom - editQueueIdTo + 1;
}
for (int i = 0; i < editQueueIdCount; i++)
{
if (editQueueIdFrom < editQueueIdTo)
{
m_editQueueIdList.push_back(editQueueIdFrom + i);
}
else
{
m_editQueueIdList.push_back(editQueueIdFrom - i);
}
}
optarg = strtok(nullptr, ", ");
}
}
}
void CommandLineParser::ParseFileNameList(int argc, const char* argv[], int optind)
{
while (optind < argc)
{
m_editQueueNameList.push_back(argv[optind++]);
}
}
void CommandLineParser::ReportError(const char* errMessage)
{
m_errors = true;
printf("%s\n", errMessage);
}
|