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.\nDid you mean get or --help?"s,
string(e.
what()));
203 const char *argv18[] = {
"tageditor",
"get",
"album",
"title",
"diskpos",
"--verbose",
"--fi" };
207 CPPUNIT_FAIL(
"Exception expected.");
209 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--fi\" is unknown.\nDid you mean --files or --no-color?"s,
string(e.
what()));
216 streambuf *regularCerrBuffer = cerr.rdbuf(buffer.rdbuf());
222 cerr.rdbuf(regularCerrBuffer);
225 cerr.rdbuf(regularCerrBuffer);
226 CPPUNIT_ASSERT_EQUAL(
"Warning: The specified argument \"album\" is unknown and will be ignored.\n"s
227 "Warning: The specified argument \"title\" is unknown and will be ignored.\n"s
228 "Warning: The specified argument \"diskpos\" is unknown and will be ignored.\n"s
229 "Warning: The specified argument \"--files\" is unknown and will be ignored.\n"s
230 "Warning: The specified argument \"somefile\" is unknown and will be ignored.\n"s,
233 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
234 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
235 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
240 const char *argv4[] = {
"tageditor",
"-i",
"-vf",
"test" };
244 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
245 CPPUNIT_ASSERT(displayFileInfoArg.
isPresent());
247 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
250 CPPUNIT_ASSERT(!strcmp(fileArg.
values().at(0),
"test"));
251 CPPUNIT_ASSERT_THROW(fileArg.
values().at(1), out_of_range);
257 CPPUNIT_FAIL(
"Exception expected.");
259 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
260 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" mustn't be specified more than 1 time."));
267 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
273 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
276 const char *argv5[] = {
"tageditor",
"-i",
"-f",
"test" };
280 CPPUNIT_FAIL(
"Exception expected.");
282 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
283 CPPUNIT_ASSERT(!strcmp(e.
what(),
"The argument \"verbose\" must be specified at least 1 time."));
288 const char *argv10[] = {
"tageditor",
"-pf",
"test" };
291 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
292 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
295 CPPUNIT_ASSERT_EQUAL(1_st, filesArg.
values(0).size());
296 CPPUNIT_ASSERT(!strcmp(filesArg.
values(0).front(),
"test"));
297 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
300 const char *argv6[] = {
"tageditor",
"-g" };
303 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
306 const char *argv7[] = {
"tageditor",
"-f",
"test" };
310 CPPUNIT_FAIL(
"Exception expected.");
312 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
313 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"-f\" is unknown.\nDid you mean get or --help?"s,
string(e.
what()));
317 const char *argv11[] = {
"tageditor",
"-if=test-v" };
323 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
324 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
325 const char *argv15[] = {
"tageditor",
"-i",
"--file=test",
"-v" };
331 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
332 CPPUNIT_ASSERT_EQUAL(
"test"s,
string(fileArg.
values(0).front()));
335 const char *argv12[] = {
"tageditor",
"-iftest" };
340 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
341 CPPUNIT_ASSERT(!strcmp(fileArg.
values(0).front(),
"test"));
344 const char *argv17[] = {
"tageditor",
"-if=test-v",
"--no-color" };
351 CPPUNIT_ASSERT_EQUAL(1_st, fileArg.
values(0).size());
352 CPPUNIT_ASSERT_EQUAL(
"test-v"s,
string(fileArg.
values(0).front()));
355 const char *argv8[] = {
"tageditor" };
358 CPPUNIT_ASSERT(qtConfigArgs.qtWidgetsGuiArg().isPresent());
359 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
361 CPPUNIT_ASSERT(!displayTagInfoArg.
isPresent());
364 if (getenv(
"PATH")) {
366 CPPUNIT_ASSERT(!strcmp(fileArg.
firstValue(), getenv(
"PATH")));
372 const char *argv13[] = {
"tageditor",
"get",
"--fields",
"album=test",
"title",
"diskpos",
"--files",
"somefile" };
377 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
378 CPPUNIT_ASSERT(!displayFileInfoArg.
isPresent());
380 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
382 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
383 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"title"));
384 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(2),
"diskpos"));
385 CPPUNIT_ASSERT_THROW(fieldsArg.
values().at(3), out_of_range);
387 CPPUNIT_ASSERT(!strcmp(filesArg.
values().at(0),
"somefile"));
388 CPPUNIT_ASSERT(!notAlbumArg.
isPresent());
391 const char *argv9[] = {
"tageditor",
"-p",
"album",
"title",
"diskpos" };
396 CPPUNIT_FAIL(
"Exception expected.");
398 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
399 CPPUNIT_ASSERT_EQUAL(
400 "Not all parameter for argument \"fields\" provided. You have to provide the following parameter: title album artist trackpos"s,
405 const char *argv16[] = {
"tageditor",
"--hel",
"-p",
"album",
"title",
"diskpos" };
410 CPPUNIT_FAIL(
"Exception expected.");
412 CPPUNIT_ASSERT(!qtConfigArgs.qtWidgetsGuiArg().isPresent());
413 CPPUNIT_ASSERT_EQUAL(
"The specified argument \"--hel\" is unknown.\nDid you mean --help or get?"s,
string(e.
what()));
417 const char *argv14[] = {
"tageditor",
"get",
"fields",
"album=test",
"-f",
"somefile" };
421 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
423 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"album=test"));
429 CPPUNIT_ASSERT(displayTagInfoArg.
isPresent());
431 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(0),
"fields"));
432 CPPUNIT_ASSERT(!strcmp(fieldsArg.
values().at(1),
"album=test"));
441 Argument callbackArg(
"with-callback",
't',
"callback test");
444 CPPUNIT_ASSERT_EQUAL(0_st, occurrence.
index);
445 CPPUNIT_ASSERT(occurrence.
path.empty());
446 CPPUNIT_ASSERT_EQUAL(2_st, occurrence.
values.size());
447 CPPUNIT_ASSERT(!strcmp(occurrence.
values[0],
"val1"));
448 CPPUNIT_ASSERT(!strcmp(occurrence.
values[1],
"val2"));
451 Argument noCallbackArg(
"no-callback",
'l',
"callback test");
456 const char *argv[] = {
"test",
"-t",
"val1",
"val2" };
460 CPPUNIT_ASSERT_EQUAL(i, 42);
465 const char *argv2[] = {
"test",
"-l",
"val1",
"val2" };
472 static bool exitCalled =
false;
482 Argument verboseArg(
"verbose",
'v',
"be verbose");
484 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
487 Argument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg");
488 Argument subArg(
"sub",
'\0',
"sub arg");
490 Argument displayFileInfoArg(
"display-file-info",
'i',
"displays general file information");
492 displayFileInfoArg.
setSubArguments({ &filesArg, &verboseArg, &subArg });
493 Argument fieldsArg(
"fields",
'\0',
"specifies the fields");
497 Argument valuesArg(
"values",
'\0',
"specifies the fields");
501 valuesArg.
setValueCompletionBehavior(ValueCompletionBehavior::PreDefinedValues | ValueCompletionBehavior::AppendEquationSign);
502 Argument selectorsArg(
"selectors",
'\0',
"has some more pre-defined values");
509 Argument getArg(
"get",
'g',
"gets tag values");
511 Argument setArg(
"set",
's',
"sets tag values");
514 parser.
setMainArguments({ &helpArg, &displayFileInfoArg, &getArg, &setArg });
517 const char *
const argv1[] = {
"se" };
521 CPPUNIT_ASSERT(reader.
read());
522 parser.printBashCompletion(1, argv1, 0, reader);
531 parser.printBashCompletion(1, argv1, 0, reader);
535 const char *
const argv2[] = {
"set" };
540 parser.printBashCompletion(1, argv2, 0, reader);
546 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
548 parser.printBashCompletion(1, argv2, 1, reader);
555 const OutputCheck c(
"COMPREPLY=('files' '--selectors' '--values' )\n");
557 parser.printBashCompletion(1, argv2, 1, reader);
564 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
566 parser.printBashCompletion(0,
nullptr, 0, reader);
570 const char *
const argv3[] = {
"get",
"--fields" };
573 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--files' )\n");
575 parser.printBashCompletion(2, argv3, 2, reader);
579 const char *
const argv4[] = {
"set",
"--values",
"a" };
582 const OutputCheck c(
"COMPREPLY=('album=' 'artist=' ); compopt -o nospace\n");
584 parser.printBashCompletion(3, argv4, 2, reader);
588 const char *
const argv12[] = {
"set",
"--selectors",
"tag=id3" };
591 const OutputCheck c(
"COMPREPLY=('tag=id3v1' 'tag=id3v2' )\n");
593 parser.printBashCompletion(3, argv12, 2, reader);
597 const char *
const argv13[] = {
"set",
"--selectors",
"tag",
"=",
"id3" };
600 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' )\n");
602 parser.printBashCompletion(5, argv13, 4, reader);
606 const OutputCheck c(
"COMPREPLY=('id3v1' 'id3v2' 'matroska' )\n");
608 parser.printBashCompletion(5, argv13, 3, reader);
615 const OutputCheck c(
"COMPREPLY=('matroska' 'mp4' 'vorbis' )\n");
617 parser.printBashCompletion(5, argv13, 3, reader);
623 const OutputCheck c(
"COMPREPLY=('title' 'album' 'artist' 'trackpos' '--fields' '--files' )\n");
625 parser.printBashCompletion(1, argv3, 2, reader);
630 iniFilePath.resize(iniFilePath.size() - 4);
632 mkvFilePath.resize(mkvFilePath.size() - 17);
634 const char *
const argv5[] = {
"get",
"--files", iniFilePath.c_str() };
637 const OutputCheck c(
"COMPREPLY=('" % mkvFilePath %
" '\"'\"'with quote'\"'\"'.mkv' '" % iniFilePath +
".ini' ); compopt -o filenames\n",
638 "COMPREPLY=('" % iniFilePath %
".ini' '" % mkvFilePath +
" '\"'\"'with quote'\"'\"'.mkv' ); compopt -o filenames\n");
640 parser.printBashCompletion(3, argv5, 2, reader);
644 const char *
const argv6[] = {
"set",
"--" };
647 const OutputCheck c(
"COMPREPLY=('--files' '--selectors' '--values' )\n");
649 parser.printBashCompletion(2, argv6, 1, reader);
653 const char *
const argv7[] = {
"-i",
"--sub",
"--" };
656 const OutputCheck c(
"COMPREPLY=('--files' '--nested-sub' '--verbose' )\n");
658 parser.printBashCompletion(3, argv7, 2, reader);
662 const char *
const argv8[] = {
"set",
"--values",
"t" };
665 const OutputCheck c(
"COMPREPLY=('title=' 'trackpos=' ); compopt -o nospace\n");
667 parser.printBashCompletion(3, argv8, 2, reader);
671 const char *
const argv9[] = {
"-gf" };
676 parser.printBashCompletion(1, argv9, 0, reader);
680 const OutputCheck c([](
const string &actualOutput) { CPPUNIT_ASSERT_EQUAL(0_st, actualOutput.find(
"COMPREPLY=('--fields' ")); });
682 parser.printBashCompletion(1, argv9, 1, reader);
689 const char *
const argv10[] = {
"/some/path/tageditor",
"--bash-completion-for",
"0" };
692 const OutputCheck c(
"COMPREPLY=('display-file-info' 'get' 'set' '--help' )\n");
695 CPPUNIT_ASSERT(!strcmp(
"/some/path/tageditor", parser.
executable()));
696 CPPUNIT_ASSERT(exitCalled);
699 const char *
const argv11[] = {
"/some/path/tageditor",
"--bash-completion-for",
"ge" };
715 CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(4 + 3), indent.
level);
721 OperationArgument verboseArg(
"verbose",
'v',
"be verbose",
"actually not an operation");
723 ConfigValueArgument nestedSubArg(
"nested-sub",
'\0',
"nested sub arg", {
"value1",
"value2" });
725 Argument subArg(
"foo",
'f',
"dummy");
732 Argument filesArg(
"files",
'f',
"specifies the path of the file(s) to be opened");
736 Argument envArg(
"env",
'\0',
"env");
747 const char *
const argv[] = {
"app",
"-h" };
749 const OutputCheck c(
"\e[1m" APP_NAME
", version " APP_VERSION
"\n" 750 "\e[0mLinked against: somelib, some other lib\n" 752 "Available operations:\n" 753 "\e[1mverbose, -v\e[0m\n" 755 " example: actually not an operation\n" 757 "Available top-level options:\n" 758 "\e[1m--files, -f\e[0m\n" 759 " specifies the path of the file(s) to be opened\n" 762 " particularities: mandatory if parent argument is present\n" 763 " \e[1m--nested-sub\e[0m [value1] [value2] ...\n" 765 " example: sub arg example\n" 767 "\e[1m--env\e[0m [file] [value 2]\n" 769 " default environment variable: FILES\n" 771 "Project website: " APP_URL
"\n");
778 const OutputCheck c(APP_NAME
", version " APP_VERSION
"\n" 779 "Linked against: somelib, some other lib\n" 781 "Available arguments:\n" 784 " example: actually not an operation\n" 787 " specifies the path of the file(s) to be opened\n" 790 " particularities: mandatory if parent argument is present\n" 791 " --nested-sub [value1] [value2] ...\n" 793 " example: sub arg example\n" 795 "--env [file] [value 2]\n" 797 " default environment variable: FILES\n" 799 "Project website: " APP_URL
"\n");
813 Argument subArg(
"sub-arg",
's',
"mandatory sub arg");
818 CPPUNIT_ASSERT_MESSAGE(
"clear main args", parser.
mainArguments().empty());
820 CPPUNIT_ASSERT_MESSAGE(
"no default due to required sub arg", !parser.
defaultArgument());
823 CPPUNIT_ASSERT_MESSAGE(
"default if no required sub arg", &helpArg == parser.
defaultArgument());
835 NoColorArgument::s_instance =
nullptr;
838 unsetenv(
"ENABLE_ESCAPE_CODES");
842 noColorArg.m_occurrences.emplace_back(0);
846 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"s_instance not altered by 2nd instance", &noColorArg, NoColorArgument::s_instance);
849 setenv(
"ENABLE_ESCAPE_CODES",
" 0 ", 1);
854 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.
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...
bool read()
Reads the commands line arguments specified when constructing the object.
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.
CPP_UTILITIES_EXPORT std::vector< const char * > dependencyVersions2
Specifies the dependency versions the application was linked against (used by ArgumentParser::printHe...
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.
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.