23 #if defined(__GNUC__) || defined(__clang__) 24 #define DEPRECATED __attribute__((deprecated)) 25 #elif defined(_MSC_VER) 26 #define DEPRECATED __declspec(deprecated) 28 #pragma message("WARNING: You need to implement DEPRECATED for this compiler") 34 Param, DataType, DataRange
38 #if defined(__GNUC__) && (__GNUC__ < 5) 39 static const char *SeparatorStrings[] = {
":",
"%",
"*" };
41 static std::vector< std::string > SeparatorStrings = {
":",
"%",
"*" };
45 static inline std::string getSeparator(
int enumVal)
47 return SeparatorStrings[enumVal];
54 const std::string &toReplace,
55 const std::string &replaceWith)
57 std::string return_string = entireString;
58 for (
size_t pos = 0;; pos += replaceWith.length())
60 pos = return_string.find(toReplace, pos);
61 if (pos == std::string::npos)
64 return_string.erase(pos, toReplace.length());
65 return_string.insert(pos, replaceWith);
90 FILE, DIRECTORY, STRING, INTEGER, FLOAT, BOOLEAN, NONE
95 int dataType_enumCode;
96 std::string dataType_string;
97 std::string dataRange;
98 std::string descriptionLine1;
99 std::string descriptionLine2;
107 Parameter(
const std::string &in_laconic,
const std::string &in_verbose,
const int &in_dataType,
const std::string &in_dataRange,
108 const std::string &in_descriptionLine1,
const std::string &in_descriptionLine2 =
"",
const std::string &in_descriptionLine3 =
"",
109 const std::string &in_descriptionLine4 =
"",
const std::string &in_descriptionLine5 =
"") :
110 laconic(in_laconic), verbose(in_verbose), dataType_enumCode(in_dataType), dataType_string(
""), dataRange(in_dataRange),
111 descriptionLine1(in_descriptionLine1), descriptionLine2(in_descriptionLine2),
118 length = laconic.length() + verbose.length();
124 dataType_string =
"FILE";
127 dataType_string =
"DIRECTORY";
130 dataType_string =
"STRING";
133 dataType_string =
"INTEGER";
136 dataType_string =
"FLOAT";
139 dataType_string =
"BOOL";
142 dataType_string =
"NONE";
145 dataType_string =
"UNKNOWN";
151 Parameter(
const std::string &in_laconic,
const std::string &in_verbose,
const std::string &in_dataType,
const std::string &in_dataRange,
152 const std::string &in_descriptionLine1,
const std::string &in_descriptionLine2 =
"",
const std::string &in_descriptionLine3 =
"",
153 const std::string &in_descriptionLine4 =
"",
const std::string &in_descriptionLine5 =
"") :
154 laconic(in_laconic), verbose(in_verbose), dataType_enumCode(0), dataType_string(in_dataType), dataRange(in_dataRange),
155 descriptionLine1(in_descriptionLine1), descriptionLine2(in_descriptionLine2),
162 length = laconic.length() + verbose.length();
165 if (dataType_string ==
"FILE")
167 dataType_enumCode = FILE;
169 else if (dataType_string ==
"DIRECTORY")
171 dataType_enumCode = DIRECTORY;
173 else if (dataType_string ==
"STRING")
175 dataType_enumCode = STRING;
177 else if (dataType_string ==
"INTEGER")
179 dataType_enumCode = INTEGER;
181 else if (dataType_string ==
"FLOAT")
183 dataType_enumCode = FLOAT;
185 else if ((dataType_string ==
"BOOL") || (dataType_string ==
"BOOLEAN"))
187 dataType_enumCode = BOOLEAN;
189 else if (dataType_string ==
"NONE")
191 dataType_enumCode = NONE;
195 dataType_enumCode = -1;
217 // add parameters to the variable
218 parser.addOptionalParameter("m","marvel", cbica::Parameter::INTEGER, "1 to 10", "I like The Avengers");
219 parser.addOptionalParameter("d", "dc", cbica::Parameter::FLOAT, "1.00 to 10.00", "I prefer the Justice League");
220 parser.addRequiredParameter("p", "people", cbica::Parameter::STRING, "max length = 1024", "People are always required");
222 // note that there should be no spaces for either of the parameter types; they will be removed.
226 std::string peopleString;
227 parser.getParameterValue("p", peopleString);
229 int marvelValue = 5; // set default value
230 parser.getParameterValue("m", marvelValue);
232 float dcValue = 5.15; // set default value
233 parser.getParameterValue("d", dcValue);
235 doSomethingWithTheParameters( peopleString, marvelValue, dcValue );
248 explicit CmdParser(
const int argc,
char **argv,
const std::string &exe_name =
"");
257 explicit CmdParser(
const int argc,
const char **argv,
const std::string &exe_name =
"");
267 void setExeName(
const std::string exeName){ m_exeName = exeName; };
289 void addParameter(
const std::string &laconic,
const std::string &verbose,
const int &expectedDataType,
const std::string &dataRange,
290 const std::string &description_line1,
const std::string &description_line2 =
"",
const std::string &description_line3 =
"",
291 const std::string &description_line4 =
"",
const std::string &description_line5 =
"");
308 void addOptionalParameter(
const std::string &laconic,
const std::string &verbose,
const int &expectedDataType,
const std::string &dataRange,
309 const std::string &description_line1,
const std::string &description_line2 =
"",
const std::string &description_line3 =
"",
310 const std::string &description_line4 =
"",
const std::string &description_line5 =
"");
327 void addRequiredParameter(
const std::string &laconic,
const std::string &verbose,
const int &expectedDataType,
const std::string &dataRange,
328 const std::string &description_line1,
const std::string &description_line2 =
"",
const std::string &description_line3 =
"",
329 const std::string &description_line4 =
"",
const std::string &description_line5 =
"");
355 bool compareParameter(
const std::string &execParamToCheck,
int &position,
bool automaticEcho =
true);
365 bool compareParameter(
const std::string &execParamToCheck,
bool automaticEcho =
true);
375 bool isPresent(
const std::string &execParamToCheck,
bool automaticEcho =
true);
386 std::string
getDescription(
const std::string &execParamToCheck,
bool NewLine);
438 DEPRECATED
void exampleUsage(
const std::string &usageOfExe);
449 void addExampleUsage(
const std::string &commandExcludingExeName,
const std::string &descriptionOfCommand);
465 void writeCWLFile(
const std::string & dirName,
bool overwriteFile);
475 std::string GetCommandFromCWL(
const std::string &inpDir,
const std::string & cwlDir);
487 void readCWLFile(
const std::string & path_to_config_file,
bool getDescription);
499 void createNode(
const std::string & nodeString);
511 void deleteNode(
const std::string & nodeString);
523 void addInputs(
const std::string & param);
535 void addOutputs(
const std::string & param);
547 std::string checkDefault(
const std::string & param);
559 void cwlrunner(
const std::string & cwl_spec_path,
const std::string & cwl_input_path,
bool getDefaultFlag);
569 std::string
getLaconic(
const std::string &execParamToCheck);
579 void getParameterValue(
const std::string &execParamToCheck,
bool ¶meterValue);
589 void getParameterValue(
const std::string &execParamToCheck,
int ¶meterValue);
599 void getParameterValue(
const std::string &execParamToCheck,
size_t ¶meterValue);
609 void getParameterValue(
const std::string &execParamToCheck,
float ¶meterValue);
619 void getParameterValue(
const std::string &execParamToCheck, std::string ¶meterValue);
630 std::string m_exeName;
632 std::string m_exePath;
634 std::string m_version;
636 std::string m_exampleOfUsage;
638 std::string m_description;
642 std::vector< std::string > m_argv;
644 std::vector< Parameter > m_requiredParameters, m_optionalParameters;
656 inline void initializeClass(
int &input_argc, std::vector< std::string > &input_argv,
const std::string &input_exeName =
"");
658 inline void getMaxLength();
660 inline void verbose_check(std::string &input_string);
662 inline void writeParameters(
const std::vector< Parameter > &inputParameters,
bool verbose);
664 void logCWL(
const std::string &inpFileName,
const std::string &cwlFileName);
667 std::vector< std::pair< std::string, std::string > > m_exampleUsageAndDescription;
670 size_t m_maxLaconicLength,
Parameter(const std::string &in_laconic, const std::string &in_verbose, const std::string &in_dataType, const std::string &in_dataRange, const std::string &in_descriptionLine1, const std::string &in_descriptionLine2="", const std::string &in_descriptionLine3="", const std::string &in_descriptionLine4="", const std::string &in_descriptionLine5="")
Constructor with five lines of description and string for dataType.
Definition: cbicaCmdParser.h:151
Parameter(const std::string &in_laconic, const std::string &in_verbose, const int &in_dataType, const std::string &in_dataRange, const std::string &in_descriptionLine1, const std::string &in_descriptionLine2="", const std::string &in_descriptionLine3="", const std::string &in_descriptionLine4="", const std::string &in_descriptionLine5="")
Constructor with five lines of description and enum_code for dataType.
Definition: cbicaCmdParser.h:107
bool compareParameter(const std::string &execParamToCheck, int &position, bool automaticEcho=true)
Check parameters WITHOUT hyphens.
CmdParser(const int argc, char **argv, const std::string &exe_name="")
The Constructor.
Holds individual parameter information.
Definition: cbicaCmdParser.h:86
std::string getExeName()
\get the executable name
Definition: cbicaCmdParser.h:272
void writeConfigFile(const std::string &dirName="")
Write the parser configuration as a JSON file.
virtual ~CmdParser()
The Destructor.
void addExampleUsage(const std::string &commandExcludingExeName, const std::string &descriptionOfCommand)
Gives a brief example of how to use the executable.
void addApplicationDescription(const std::string &description)
Adds descrition for the application for which the class is being initialized.
size_t length
defaults to blank
Definition: cbicaCmdParser.h:104
std::string getDescription(const std::string &execParamToCheck, bool NewLine)
Get the description analogous with the parameter.
void setExeName(const std::string exeName)
Set a custom executable name.
Definition: cbicaCmdParser.h:267
std::string descriptionLine5
defaults to blank
Definition: cbicaCmdParser.h:102
std::string descriptionLine3
defaults to blank
Definition: cbicaCmdParser.h:100
void echoVersion()
Display the version details.
void ignoreArgc1()
This function ensures that argc < 2 isn't checked.
Definition: cbicaCmdParser.h:622
void addParameter(const std::string &laconic, const std::string &verbose, const int &expectedDataType, const std::string &dataRange, const std::string &description_line1, const std::string &description_line2="", const std::string &description_line3="", const std::string &description_line4="", const std::string &description_line5="")
Adding parameters: defaults to optional parameters.
void addOptionalParameter(const std::string &laconic, const std::string &verbose, const int &expectedDataType, const std::string &dataRange, const std::string &description_line1, const std::string &description_line2="", const std::string &description_line3="", const std::string &description_line4="", const std::string &description_line5="")
Adding Optional parameters.
void writeCWLFile(const std::string &dirName, bool overwriteFile)
Writes out a CWL specification file from cmd parser.
DEPRECATED void exampleUsage(const std::string &usageOfExe)
Gives a brief example of how to use the executable.
void echoHelp()
Display verbose usage.
static std::vector< Parameter > readConfigFile(const std::string &inputConfigFile, bool getDescription=true)
Reads a pre-written configuration file using CmdParser::WriteConfigFile()
int getDataTypeAsEnumCode(const std::string &execParamToCheck)
Get the data type analogous with the parameter.
void addRequiredParameter(const std::string &laconic, const std::string &verbose, const int &expectedDataType, const std::string &dataRange, const std::string &description_line1, const std::string &description_line2="", const std::string &description_line3="", const std::string &description_line4="", const std::string &description_line5="")
Adding Required parameters.
void echoUsage()
Display the usage.
bool isPresent(const std::string &execParamToCheck, bool automaticEcho=true)
Check if supplied parameter is present in the argument list.
std::string getLaconic(const std::string &execParamToCheck)
Get the laconic value from verbose.
std::string stringReplace(const std::string &entireString, const std::string &toReplace, const std::string &replaceWith)
copied from cbicaUtilities to ensure CmdParser stays header-only
Definition: cbicaCmdParser.h:53
std::string descriptionLine4
defaults to blank
Definition: cbicaCmdParser.h:101
Simple command line parsing.
Definition: cbicaCmdParser.h:238
std::string getDataTypeAsString(const std::string &execParamToCheck)
Get the data type analogous with the parameter.
void getParameterValue(const std::string &execParamToCheck, bool ¶meterValue)
Get the value of the parameter.