4 #include "../conversion/stringbuilder.h" 6 #include "../application/argumentparser.h" 7 #include "../application/argumentparserprivate.h" 8 #include "../application/commandlineutils.h" 9 #include "../application/failure.h" 10 #include "../application/fakeqtconfigarguments.h" 12 #include "../io/ansiescapecodes.h" 13 #include "../io/path.h" 15 #include "resources/config.h" 17 #include <cppunit/TestFixture.h> 18 #include <cppunit/extensions/HelperMacros.h> 36 CPPUNIT_TEST(testArgument);
37 CPPUNIT_TEST(testParsing);
38 CPPUNIT_TEST(testCallbacks);
39 CPPUNIT_TEST(testBashCompletion);
40 CPPUNIT_TEST(testHelp);
41 CPPUNIT_TEST(testSetMainArguments);
42 CPPUNIT_TEST(testNoColorArgument);
43 CPPUNIT_TEST_SUITE_END();
52 void testBashCompletion();
54 void testSetMainArguments();
55 void testNoColorArgument();
76 Argument argument(
"test",
't',
"some description");
77 CPPUNIT_ASSERT_EQUAL(argument.
isRequired(),
false);
79 CPPUNIT_ASSERT_EQUAL(argument.
isRequired(),
true);
80 Argument subArg(
"sub",
's',
"sub arg");
82 CPPUNIT_ASSERT_EQUAL(subArg.parents().at(0), &argument);
83 CPPUNIT_ASSERT(!subArg.conflictsWithArgument());
86 setenv(
"FOO_ENV_VAR",
"foo",
true);
87 CPPUNIT_ASSERT(!strcmp(argument.
firstValue(),
"foo"));
89 occurrence.
values.emplace_back(
"bar");
90 argument.m_occurrences.emplace_back(move(occurrence));
91 CPPUNIT_ASSERT(!strcmp(argument.
firstValue(),
"bar"));
104 Argument verboseArg(
"verbose",
'v',
"be verbose");
106 Argument fileArg(
"file",
'f',
"specifies the path of the file to be opened");
110 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
113 Argument outputFileArg(
"output-file",
'o',
"specifies the path of the output file");
118 Argument printFieldNamesArg(
"print-field-names",
'\0',
"prints available field names");
119 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
120 Argument notAlbumArg(
"album",
'a',
"should not be confused with album value");
122 displayFileInfoArg.
setSubArguments({ &fileArg, &verboseArg, ¬AlbumArg });
123 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
125 fieldsArg.
setValueNames({
"title",
"album",
"artist",
"trackpos" });
127 Argument displayTagInfoArg(
"get",
'p',
"displays the values of all specified tag fields (displays all fields if none specified)");
129 displayTagInfoArg.
setSubArguments({ &fieldsArg, &filesArg, &verboseArg, ¬AlbumArg });
131 parser.
setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &helpArg, &noColorArg });
140 const char *argv[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"-f",
"somefile" };
144 CPPUNIT_FAIL(
"Exception expected.");
146 CPPUNIT_ASSERT_EQUAL(
"The argument \"files\" can not be combined with \"fields\"."s,
string(e.
what()));
150 CPPUNIT_ASSERT_EQUAL(
151 "Error: Unable to parse arguments: The argument \"files\" can not be combined with \"fields\".\nSee --help for available commands.\n"s,
161 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
162 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
163 CPPUNIT_ASSERT(!strcmp(parser.
executable(),
"tageditor"));
165 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
167 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
168 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
169 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
170 CPPUNIT_ASSERT_THROW(displayTagInfoArg.
values().at(3), out_of_range);
174 const char *argv2[] = {
"tageditor",
"",
"-p",
"album",
"title",
"diskpos",
"",
"--files",
"somefile" };
179 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
180 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
182 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
184 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album"));
185 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
186 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
187 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(3),
""));
188 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(4), out_of_range);
190 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
193 const char *argv3[] = {
"tageditor",
"album",
"title",
"diskpos",
"--files",
"somefile" };
197 CPPUNIT_FAIL(
"Exception expected.");
199 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"album\" is unknown."s,
string(e.
what()));
206 streambuf *regularCerrBuffer = cerr.rdbuf(buffer.rdbuf());
212 cerr.rdbuf(regularCerrBuffer);
215 cerr.rdbuf(regularCerrBuffer);
216 CPPUNIT_ASSERT_EQUAL(
"Warning: The specified argument \"album\" is unknown and will be ignored.\n"s
217 "Warning: The specified argument \"title\" is unknown and will be ignored.\n"s
218 "Warning: The specified argument \"diskpos\" is unknown and will be ignored.\n"s
219 "Warning: The specified argument \"--files\" is unknown and will be ignored.\n"s
220 "Warning: The specified argument \"somefile\" is unknown and will be ignored.\n"s,
223 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
224 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
225 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
230 const char *argv4[] = {
"tageditor",
"-i",
"-vf",
"test" };
234 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
235 CPPUNIT_ASSERT(displayFileInfoArg.
isPresent());
237 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
240 CPPUNIT_ASSERT(!strcmp(fileArg.
values().at(0),
"test"));
241 CPPUNIT_ASSERT_THROW(fileArg.
values().at(1), out_of_range);
247 CPPUNIT_FAIL(
"Exception expected.");
249 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
250 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" mustn't be specified more than 1 time."));
257 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
263 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
266 const char *argv5[] = {
"tageditor",
"-i",
"-f",
"test" };
270 CPPUNIT_FAIL(
"Exception expected.");
272 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
273 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" must be specified at least 1 time."));
278 const char *argv10[] = {
"tageditor",
"-pf",
"test" };
281 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
282 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
285 CPPUNIT_ASSERT_EQUAL(1_st, filesArg.
values(0).size());
286 CPPUNIT_ASSERT(!strcmp(filesArg.
values(0).front(),
"test"));
287 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
290 const char *argv6[] = {
"tageditor",
"-g" };
293 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
296 const char *argv7[] = {
"tageditor",
"-f",
"test" };
300 CPPUNIT_FAIL(
"Exception expected.");
302 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
303 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"-f\" is unknown."s,
string(e.
what()));
307 const char *argv11[] = {
"tageditor",
"-if=test-v" };
313 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
314 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
315 const char *argv15[] = {
"tageditor",
"-i",
"--file=test",
"-v" };
321 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
322 CPPUNIT_ASSERT_EQUAL(
"test"s,
string(fileArg.
values(0).front()));
325 const char *argv12[] = {
"tageditor",
"-iftest" };
330 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
331 CPPUNIT_ASSERT(!strcmp(fileArg.
values(0).front(),
"test"));
334 const char *argv17[] = {
"tageditor",
"-if=test-v",
"--no-color" };
341 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
342 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
345 const char *argv8[] = {
"tageditor" };
348 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
349 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
351 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
354 if (getenv(
"PATH")) {
356 CPPUNIT_ASSERT(!strcmp(fileArg.
firstValue(), getenv(
"PATH")));
362 const char *argv13[] = {
"tageditor",
"get",
"--fields",
"album=test",
"title",
"diskpos",
"--files",
"somefile" };
367 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
368 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
370 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
372 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
373 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
374 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
375 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(3), out_of_range);
377 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
378 CPPUNIT_ASSERT(!notAlbumArg.
isPresent());
381 const char *argv9[] = {
"tageditor",
"-p",
"album",
"title",
"diskpos" };
386 CPPUNIT_FAIL(
"Exception expected.");
388 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
389 CPPUNIT_ASSERT_EQUAL(
390 "Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"s,
395 const char *argv16[] = {
"tageditor",
"--hel",
"-p",
"album",
"title",
"diskpos" };
400 CPPUNIT_FAIL(
"Exception expected.");
402 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
403 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--hel\" is unknown."s,
string(e.
what()));
407 const char *argv14[] = {
"tageditor",
"get",
"fields",
"album=test",
"-f",
"somefile" };
411 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
413 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
419 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
421 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"fields"));
422 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"album=test"));
431 Argument callbackArg(
"with-callback",
't',
"callback test");
434 CPPUNIT_ASSERT_EQUAL(0_st, occurrence.
index);
435 CPPUNIT_ASSERT(occurrence.
path.empty());
436 CPPUNIT_ASSERT_EQUAL(2_st, occurrence.
values.size());
437 CPPUNIT_ASSERT(!strcmp(occurrence.
values[0],
"val1"));
438 CPPUNIT_ASSERT(!strcmp(occurrence.
values[1],
"val2"));
441 Argument noCallbackArg(
"no-callback",
'l',
"callback test");
446 const char *argv[] = {
"test",
"-t",
"val1",
"val2" };
450 CPPUNIT_ASSERT_EQUAL(i, 42);
455 const char *argv2[] = {
"test",
"-l",
"val1",
"val2" };
462 static bool exitCalled =
false;
472 Argument verboseArg(
"verbose",
'v',
"be verbose");
474 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
477 Argument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg");
478 Argument subArg(
"sub",
'\0',
"sub arg");
480 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
482 displayFileInfoArg.
setSubArguments({ &filesArg, &verboseArg, &subArg });
483 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
487 Argument valuesArg(
"values",
'\0',
"specifies the fields");
491 valuesArg.
setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
492 Argument selectorsArg(
"selectors",
'\0',
"has some more pre-defined values");
499 Argument getArg(
"get",
'g',
"gets tag values");
501 Argument setArg(
"set",
's',
"sets tag values");
504 parser.
setMainArguments({ &helpArg, &displayFileInfoArg, &getArg, &setArg });
507 const char *
const argv1[] = {
"se" };
512 parser.printBashCompletion(1, argv1, 0, reader);
521 parser.printBashCompletion(1, argv1, 0, reader);
525 const char *
const argv2[] = {
"set" };
530 parser.printBashCompletion(1, argv2, 0, reader);
536 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
538 parser.printBashCompletion(1, argv2, 1, reader);
545 const OutputCheck c(
"COMPREPLY=('files' '--selectors' '--values' )\n");
547 parser.printBashCompletion(1, argv2, 1, reader);
554 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
556 parser.printBashCompletion(0,
nullptr, 0, reader);
560 const char *
const argv3[] = {
"get",
"--fields" };
563 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n");
565 parser.printBashCompletion(2, argv3, 2, reader);
569 const char *
const argv4[] = {
"set",
"--values",
"a" };
572 const OutputCheck c(
"COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n");
574 parser.printBashCompletion(3, argv4, 2, reader);
578 const char *
const argv12[] = {
"set",
"--selectors",
"tag=id3" };
581 const OutputCheck c(
"COMPREPLY=('tag=id3v1' 'tag=id3v2' )\n");
583 parser.printBashCompletion(3, argv12, 2, reader);
587 const char *
const argv13[] = {
"set",
"--selectors",
"tag",
"=",
"id3" };
590 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' )\n");
592 parser.printBashCompletion(5, argv13, 4, reader);
596 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' 'matroska' )\n");
598 parser.printBashCompletion(5, argv13, 3, reader);
605 const OutputCheck c(
"COMPREPLY=('matroska' 'mp4' 'vorbis' )\n");
607 parser.printBashCompletion(5, argv13, 3, reader);
613 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--fields' '--files' )\n");
615 parser.printBashCompletion(1, argv3, 2, reader);
620 iniFilePath.resize(iniFilePath.size() - 4);
622 mkvFilePath.resize(mkvFilePath.size() - 17);
624 const char *
const argv5[] = {
"get",
"--files", iniFilePath.c_str() };
627 const OutputCheck c(
"COMPREPLY=('" % mkvFilePath %
" '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath +
".ini' ); compopt -o filenames\n",
628 "COMPREPLY=('" % iniFilePath %
".ini' '" % mkvFilePath +
" '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
630 parser.printBashCompletion(3, argv5, 2, reader);
634 const char *
const argv6[] = {
"set",
"--" };
637 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
639 parser.printBashCompletion(2, argv6, 1, reader);
643 const char *
const argv7[] = {
"-i",
"--sub",
"--" };
646 const OutputCheck c(
"COMPREPLY=('--files' '--nested-sub' '--verbose' )\n");
648 parser.printBashCompletion(3, argv7, 2, reader);
652 const char *
const argv8[] = {
"set",
"--values",
"t" };
655 const OutputCheck c(
"COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n");
657 parser.printBashCompletion(3, argv8, 2, reader);
661 const char *
const argv9[] = {
"-gf" };
666 parser.printBashCompletion(1, argv9, 0, reader);
670 const OutputCheck c([](
const string &actualOutput) { CPPUNIT_ASSERT_EQUAL(0_st, actualOutput.find(
"COMPREPLY=('--fields' ")); });
672 parser.printBashCompletion(1, argv9, 1, reader);
679 const char *
const argv10[] = {
"/some/path/tageditor",
"--bash-completion-for",
"0" };
682 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
685 CPPUNIT_ASSERT(!strcmp(
"/some/path/tageditor", parser.
executable()));
686 CPPUNIT_ASSERT(exitCalled);
689 const char *
const argv11[] = {
"/some/path/tageditor",
"--bash-completion-for",
"ge" };
705 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(4 + 3), indent.
level);
711 OperationArgument verboseArg(
"verbose",
'v',
"be verbose",
"actually not an operation");
713 ConfigValueArgument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg", {
"value1",
"value2" });
715 Argument subArg(
"foo",
'f',
"dummy");
722 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
726 Argument envArg(
"env",
'\0',
"env");
737 const char *
const argv[] = {
"app",
"-h" };
739 const OutputCheck c(
"\e[1m" APP_NAME
", version " APP_VERSION
"\n" 740 "\e[0mLinked against: somelib, some other lib\n" 742 "Available operations:\n" 743 "\e[1mverbose, -v\e[0m\n" 745 " example: actually not an operation\n" 747 "Available top-level options:\n" 748 "\e[1m--files, -f\e[0m\n" 749 " specifies the path of the file(s) to be opened\n" 752 " particularities: mandatory if parent argument is present\n" 753 " \e[1m--nested-sub\e[0m [value1] [value2] ...\n" 755 " example: sub arg example\n" 757 "\e[1m--env\e[0m [file] [value 2]\n" 759 " default environment variable: FILES\n" 761 "Project website: " APP_URL
"\n");
768 const OutputCheck c(APP_NAME
", version " APP_VERSION
"\n" 769 "Linked against: somelib, some other lib\n" 771 "Available arguments:\n" 774 " example: actually not an operation\n" 777 " specifies the path of the file(s) to be opened\n" 780 " particularities: mandatory if parent argument is present\n" 781 " --nested-sub [value1] [value2] ...\n" 783 " example: sub arg example\n" 785 "--env [file] [value 2]\n" 787 " default environment variable: FILES\n" 789 "Project website: " APP_URL
"\n");
803 Argument subArg(
"sub-arg",
's',
"mandatory sub arg");
808 CPPUNIT_ASSERT_MESSAGE(
"clear main args", parser.
mainArguments().empty());
810 CPPUNIT_ASSERT_MESSAGE(
"no default due to required sub arg", !parser.
defaultArgument());
813 CPPUNIT_ASSERT_MESSAGE(
"default if no required sub arg", &helpArg == parser.
defaultArgument());
825 NoColorArgument::s_instance =
nullptr;
828 unsetenv(
"ENABLE_ESCAPE_CODES");
832 noColorArg.m_occurrences.emplace_back(0);
836 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"s_instance not altered by 2nd instance", &noColorArg, NoColorArgument::s_instance);
839 setenv(
"ENABLE_ESCAPE_CODES",
" 0 ", 1);
844 setenv(
"ENABLE_ESCAPE_CODES",
" 1 ", 1);
void testNoColorArgument()
Tests whether NocolorArgument toggles escape codes correctly.
void testBashCompletion()
Tests bash completion.
void resetArgs()
Resets all Argument instances assigned as mainArguments() and sub arguments.
#define QT_CONFIG_ARGUMENTS
The ConfigValueArgument class is an Argument where setCombinable() is true by default.
Argument * defaultArgument() const
Returns the default argument.
void setImplicit(bool value)
Sets whether the argument is an implicit argument.
std::size_t index
The index of the occurrence.
void testParsing()
Tests parsing command line arguments.
static void apply()
Sets EscapeCodes::enabled according to the presense of the first instantiation of NoColorArgument...
void setCombinable(bool value)
Sets whether this argument can be combined.
ValueCompletionBehavior valueCompletionBehaviour() const
Returns the items to be considered when generating completion for the values.
void setUnknownArgumentBehavior(UnknownArgumentBehavior behavior)
Sets how unknown arguments are treated.
void readArgs(int argc, const char *const *argv)
Parses the specified command line arguments.
virtual const char * what() const USE_NOTHROW
Returns a C-style character string describing the cause of the Failure.
Contains currently only ArgumentParser and related classes.
void setMainArguments(const ArgumentInitializerList &mainArguments)
Sets the main arguments for the parser.
void testArgument()
Tests the behaviour of the argument class.
void testSetMainArguments()
Tests some corner cases in setMainArguments() which are not already checked in the other tests...
bool isRequired() const
Returns an indication whether the argument is mandatory.
void testCallbacks()
Tests whether callbacks are called correctly.
void setRequired(bool required)
Sets whether this argument is mandatory or not.
Contains literals to ease asserting with CPPUNIT_ASSERT_EQUAL.
void parseArgs(int argc, const char *const *argv)
Parses the specified command line arguments.
const char * firstValue() const
Returns the first parameter value of the first occurrence of the argument.
The Indentation class allows printing indentation conveniently, eg.
The NoColorArgument class allows to specify whether use of escape codes or similar technique to provi...
void addMainArgument(Argument *argument)
Adds the specified argument to the main argument.
The ArgumentParserTests class tests the ArgumentParser and Argument classes.
The OperationArgument class is an Argument where denotesOperation() is true by default.
void setConstraints(std::size_t minOccurrences, std::size_t maxOccurrences)
Sets the allowed number of occurrences.
void setAbbreviation(char abbreviation)
Sets the abbreviation of the argument.
Contains classes and functions utilizing creating of test applications.
void setDescription(const char *description)
Sets the description of the argument.
CPP_UTILITIES_EXPORT bool enabled
Controls whether the functions inside the EscapeCodes namespace actually make use of escape codes...
void setValueCompletionBehavior(ValueCompletionBehavior valueCompletionBehaviour)
Sets the items to be considered when generating completion for the values.
#define SET_APPLICATION_INFO
Sets application meta data (including SET_DEPENDENCY_INFO) used by ArgumentParser::printHelp().
void appendValueName(const char *valueName)
Appends a value name.
CPP_UTILITIES_EXPORT std::initializer_list< const char * > dependencyVersions
Specifies the dependency versions the application was linked against (used by ArgumentParser::printHe...
const std::vector< const char * > & values(std::size_t occurrence=0) const
Returns the parameter values for the specified occurrence of argument.
Contains several functions providing conversions between different data types.
CPP_UTILITIES_EXPORT void(* exitFunction)(int)
Specifies a function quit the application.
const char * executable() const
Returns the name of the current executable.
The Argument class is a wrapper for command line argument information.
void setCallback(CallbackFunction callback)
Sets a callback function which will be called by the parser if the argument could be found and no par...
void setExample(const char *example)
Sets the a usage example for the argument.
void setPreDefinedCompletionValues(const char *preDefinedCompletionValues)
Assignes the values to be used when generating completion for the values.
ApplicationUtilities::ArgumentReader & reset(const char *const *argv, const char *const *end)
Resets the ArgumentReader to continue reading new argv.
std::vector< Argument * > path
The "path" of the occurrence (the parent elements which have been specified before).
The StandardOutputCheck class asserts whether the (standard) output written in the enclosing code blo...
void addSubArgument(Argument *arg)
Adds arg as a secondary argument for this argument.
void setEnvironmentVariable(const char *environmentVariable)
Sets the environment variable queried when firstValue() is called.
The ArgumentOccurrence struct holds argument values for an occurrence of an argument.
bool isPresent() const
Returns an indication whether the argument could be detected when parsing.
The HelpArgument class prints help information for an argument parser when present (–help...
CPPUNIT_TEST_SUITE_REGISTRATION(ArgumentParserTests)
The Failure class is thrown by an ArgumentParser when a parsing error occurs.
const ArgumentVector & mainArguments() const
Returns the main arguments.
void setDenotesOperation(bool denotesOperation)
Sets whether the argument denotes the operation.
bool isUncombinableMainArgPresent() const
Checks whether at least one uncombinable main argument is present.
void reset()
Resets occurrences (indices, values and paths).
void setRequiredValueCount(std::size_t requiredValueCount)
Sets the number of values which are required to be given for this argument.
The ArgumentReader class internally encapsulates the process of reading command line arguments...
void setSubArguments(const ArgumentInitializerList &subArguments)
Sets the secondary arguments for this arguments.
unsigned int actualArgumentCount() const
Returns the actual number of arguments that could be found when parsing.
void setName(const char *name)
Sets the name of the argument.
void read()
Reads the commands line arguments specified when constructing the object.
CPP_UTILITIES_EXPORT std::string testFilePath(const std::string &name)
Convenience function which returns the full path of the test file with the specified name...
The ArgumentParser class provides a means for handling command line arguments.
Argument * specifiedOperation() const
Returns the first operation argument specified by the user or nullptr if no operation has been specif...
void testHelp()
Tests –help output.
void setValueNames(std::initializer_list< const char *> valueNames)
Sets the names of the requried values.
std::vector< const char * > values
The parameter values which have been specified after the occurrence of the argument.