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
|
/*
* 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/>.
*/
#ifndef COMMANDLINEPARSER_H
#define COMMANDLINEPARSER_H
#include "NString.h"
class CommandLineParser
{
public:
enum EClientOperation
{
opClientNoOperation,
opClientRequestDownload,
opClientRequestListFiles,
opClientRequestListGroups,
opClientRequestListStatus,
opClientRequestSetRate,
opClientRequestDumpDebug,
opClientRequestEditQueue,
opClientRequestLog,
opClientRequestShutdown,
opClientRequestReload,
opClientRequestVersion,
opClientRequestPostQueue,
opClientRequestWriteLog,
opClientRequestScanSync,
opClientRequestScanAsync,
opClientRequestDownloadPause,
opClientRequestDownloadUnpause,
opClientRequestPostPause,
opClientRequestPostUnpause,
opClientRequestScanPause,
opClientRequestScanUnpause,
opClientRequestHistory,
opClientRequestHistoryAll
};
enum EMatchMode
{
mmId = 1,
mmName,
mmRegEx
};
typedef std::vector<int> IdList;
typedef std::vector<CString> NameList;
CommandLineParser(int argc, const char* argv[]);
void PrintUsage(const char* com);
bool GetErrors() { return m_errors; }
bool GetNoConfig() { return m_noConfig; }
const char* GetConfigFilename() { return m_configFilename; }
bool GetServerMode() { return m_serverMode; }
bool GetDaemonMode() { return m_daemonMode; }
bool GetRemoteClientMode() { return m_remoteClientMode; }
EClientOperation GetClientOperation() { return m_clientOperation; }
NameList* GetOptionList() { return &m_optionList; }
int GetEditQueueAction() { return m_editQueueAction; }
int GetEditQueueOffset() { return m_editQueueOffset; }
IdList* GetEditQueueIdList() { return &m_editQueueIdList; }
NameList* GetEditQueueNameList() { return &m_editQueueNameList; }
EMatchMode GetMatchMode() { return m_matchMode; }
const char* GetEditQueueText() { return m_editQueueText; }
const char* GetArgFilename() { return m_argFilename; }
const char* GetAddCategory() { return m_addCategory; }
bool GetAddPaused() { return m_addPaused; }
const char* GetLastArg() { return m_lastArg; }
int GetAddPriority() { return m_addPriority; }
const char* GetAddNzbFilename() { return m_addNzbFilename; }
bool GetAddTop() { return m_addTop; }
const char* GetAddDupeKey() { return m_addDupeKey; }
int GetAddDupeScore() { return m_addDupeScore; }
int GetAddDupeMode() { return m_addDupeMode; }
int GetSetRate() { return m_setRate; }
int GetLogLines() { return m_logLines; }
int GetWriteLogKind() { return m_writeLogKind; }
bool GetTestBacktrace() { return m_testBacktrace; }
bool GetWebGet() { return m_webGet; }
const char* GetWebGetFilename() { return m_webGetFilename; }
bool GetSigVerify() { return m_sigVerify; }
const char* GetPubKeyFilename() { return m_pubKeyFilename; }
const char* GetSigFilename() { return m_sigFilename; }
bool GetPrintOptions() { return m_printOptions; }
bool GetPrintVersion() { return m_printVersion; }
bool GetPrintUsage() { return m_printUsage; }
bool GetPauseDownload() const { return m_pauseDownload; }
private:
bool m_noConfig = false;
CString m_configFilename;
// Parsed command-line parameters
bool m_errors = false;
bool m_printVersion = false;
bool m_printUsage = false;
bool m_serverMode = false;
bool m_daemonMode = false;
bool m_remoteClientMode = false;
EClientOperation m_clientOperation;
NameList m_optionList;
int m_editQueueAction = 0;
int m_editQueueOffset = 0;
IdList m_editQueueIdList;
NameList m_editQueueNameList;
EMatchMode m_matchMode = mmId;
CString m_editQueueText;
CString m_argFilename;
CString m_addCategory;
int m_addPriority = 0;
bool m_addPaused = false;
CString m_addNzbFilename;
CString m_lastArg;
bool m_printOptions = false;
bool m_addTop = false;
CString m_addDupeKey;
int m_addDupeScore = 0;
int m_addDupeMode = 0;
int m_setRate = 0;
int m_logLines = 0;
int m_writeLogKind = 0;
bool m_testBacktrace = false;
bool m_webGet = false;
CString m_webGetFilename;
bool m_sigVerify = false;
CString m_pubKeyFilename;
CString m_sigFilename;
bool m_pauseDownload = false;
void InitCommandLine(int argc, const char* argv[]);
void InitFileArg(int argc, const char* argv[]);
void ParseFileIdList(int argc, const char* argv[], int optind);
void ParseFileNameList(int argc, const char* argv[], int optind);
void ReportError(const char* errMessage);
};
#endif
|