Don't pretent to add arguments implicitely
This commit is contained in:
parent
cfdfc302db
commit
6d7a6ab735
|
@ -1136,7 +1136,7 @@ inline void ArgumentParser::setExitFunction(std::function<void(int)> exitFunctio
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the `--help` argument (which is always implicitely added to the main arguments).
|
||||
* \brief Returns the `--help` argument.
|
||||
*/
|
||||
inline const HelpArgument &ArgumentParser::helpArg() const
|
||||
{
|
||||
|
@ -1144,7 +1144,7 @@ inline const HelpArgument &ArgumentParser::helpArg() const
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the `--help` argument (which is always implicitely added to the main arguments).
|
||||
* \brief Returns the `--help` argument.
|
||||
*/
|
||||
inline HelpArgument &ArgumentParser::helpArg()
|
||||
{
|
||||
|
@ -1152,7 +1152,7 @@ inline HelpArgument &ArgumentParser::helpArg()
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the `--no-color` argument (which is always implicitely added to the main arguments).
|
||||
* \brief Returns the `--no-color` argument.
|
||||
*/
|
||||
inline const NoColorArgument &ArgumentParser::noColorArg() const
|
||||
{
|
||||
|
@ -1160,7 +1160,7 @@ inline const NoColorArgument &ArgumentParser::noColorArg() const
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns the `--no-color` argument (which is always implicitely added to the main arguments).
|
||||
* \brief Returns the `--no-color` argument.
|
||||
*/
|
||||
inline NoColorArgument &ArgumentParser::noColorArg()
|
||||
{
|
||||
|
|
|
@ -151,7 +151,8 @@ void ArgumentParserTests::testParsing()
|
|||
Argument displayTagInfoArg("get", 'p', "displays the values of all specified tag fields (displays all fields if none specified)");
|
||||
displayTagInfoArg.setDenotesOperation(true);
|
||||
displayTagInfoArg.setSubArguments({ &fieldsArg, &filesArg, &verboseArg, ¬AlbumArg });
|
||||
parser.setMainArguments({ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg });
|
||||
parser.setMainArguments(
|
||||
{ &qtConfigArgs.qtWidgetsGuiArg(), &printFieldNamesArg, &displayTagInfoArg, &displayFileInfoArg, &parser.noColorArg(), &parser.helpArg() });
|
||||
|
||||
// no args present
|
||||
parser.parseArgs(0, nullptr);
|
||||
|
@ -502,7 +503,6 @@ void ArgumentParserTests::testBashCompletion()
|
|||
{
|
||||
ArgumentParser parser;
|
||||
parser.setExitFunction(std::bind(&ArgumentParserTests::failOnExit, this, std::placeholders::_1));
|
||||
HelpArgument helpArg(parser);
|
||||
Argument verboseArg("verbose", 'v', "be verbose");
|
||||
verboseArg.setCombinable(true);
|
||||
Argument filesArg("files", 'f', "specifies the path of the file(s) to be opened");
|
||||
|
@ -535,7 +535,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
Argument setArg("set", 's', "sets tag values");
|
||||
setArg.setSubArguments({ &valuesArg, &filesArg, &selectorsArg });
|
||||
|
||||
parser.setMainArguments({ &displayFileInfoArg, &getArg, &setArg });
|
||||
parser.setMainArguments({ &displayFileInfoArg, &getArg, &setArg, &parser.noColorArg(), &parser.helpArg() });
|
||||
|
||||
// fail due to operation flags not set
|
||||
const char *const argv1[] = { "se" };
|
||||
|
@ -567,7 +567,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
// advance the cursor position -> the completion should propose the next argument
|
||||
parser.resetArgs();
|
||||
{
|
||||
const OutputCheck c("COMPREPLY=('--files' '--selectors' '--no-color' '--values' )\n");
|
||||
const OutputCheck c("COMPREPLY=('--files' '--no-color' '--selectors' '--values' )\n");
|
||||
reader.reset(argv2, argv2 + 1).read();
|
||||
parser.printBashCompletion(1, argv2, 1, reader);
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
parser.resetArgs();
|
||||
filesArg.setDenotesOperation(true);
|
||||
{
|
||||
const OutputCheck c("COMPREPLY=('files' '--selectors' '--no-color' '--values' )\n");
|
||||
const OutputCheck c("COMPREPLY=('files' '--no-color' '--selectors' '--values' )\n");
|
||||
reader.reset(argv2, argv2 + 1).read();
|
||||
parser.printBashCompletion(1, argv2, 1, reader);
|
||||
}
|
||||
|
@ -668,7 +668,7 @@ void ArgumentParserTests::testBashCompletion()
|
|||
const char *const argv6[] = { "set", "--" };
|
||||
parser.resetArgs();
|
||||
{
|
||||
const OutputCheck c("COMPREPLY=('--files' '--selectors' '--no-color' '--values' )\n");
|
||||
const OutputCheck c("COMPREPLY=('--files' '--no-color' '--selectors' '--values' )\n");
|
||||
reader.reset(argv6, argv6 + 2).read();
|
||||
parser.printBashCompletion(2, argv6, 1, reader);
|
||||
}
|
||||
|
@ -743,8 +743,7 @@ void ArgumentParserTests::testHelp()
|
|||
|
||||
// setup parser
|
||||
ArgumentParser parser;
|
||||
HelpArgument helpArg(parser);
|
||||
helpArg.setRequired(true);
|
||||
parser.setExitFunction(std::bind(&ArgumentParserTests::failOnExit, this, std::placeholders::_1));
|
||||
OperationArgument verboseArg("verbose", 'v', "be verbose", "actually not an operation");
|
||||
verboseArg.setCombinable(true);
|
||||
ConfigValueArgument nestedSubArg("nested-sub", '\0', "nested sub arg", { "value1", "value2" });
|
||||
|
@ -765,9 +764,7 @@ void ArgumentParserTests::testHelp()
|
|||
envArg.setRequiredValueCount(2);
|
||||
envArg.appendValueName("file");
|
||||
parser.helpArg().setRequired(true);
|
||||
parser.addMainArgument(&verboseArg);
|
||||
parser.addMainArgument(&filesArg);
|
||||
parser.addMainArgument(&envArg);
|
||||
parser.setMainArguments({ &verboseArg, &filesArg, &envArg, &parser.noColorArg(), &parser.helpArg() });
|
||||
dependencyVersions2 = { "somelib", "some other lib" };
|
||||
|
||||
// parse args and assert output
|
||||
|
@ -805,6 +802,7 @@ void ArgumentParserTests::testHelp()
|
|||
}
|
||||
|
||||
verboseArg.setDenotesOperation(false);
|
||||
parser.setMainArguments({ &verboseArg, &filesArg, &envArg, &parser.helpArg() });
|
||||
{
|
||||
const OutputCheck c(APP_NAME ", version " APP_VERSION "\n"
|
||||
"Linked against: somelib, some other lib\n"
|
||||
|
@ -842,7 +840,7 @@ void ArgumentParserTests::testSetMainArguments()
|
|||
{
|
||||
ArgumentParser parser;
|
||||
parser.setExitFunction(std::bind(&ArgumentParserTests::failOnExit, this, std::placeholders::_1));
|
||||
HelpArgument helpArg(parser);
|
||||
HelpArgument &helpArg(parser.helpArg());
|
||||
Argument subArg("sub-arg", 's', "mandatory sub arg");
|
||||
subArg.setRequired(true);
|
||||
helpArg.addSubArgument(&subArg);
|
||||
|
|
|
@ -149,7 +149,8 @@ TestApplication::TestApplication(int argc, const char *const *argv)
|
|||
m_unitsArg.setRequiredValueCount(Argument::varValueCount);
|
||||
m_unitsArg.setValueNames({ "unit1", "unit2", "unit3" });
|
||||
m_unitsArg.setCombinable(true);
|
||||
m_parser.setMainArguments({ &m_testFilesPathArg, &m_applicationPathArg, &m_workingDirArg, &m_unitsArg });
|
||||
m_parser.setMainArguments(
|
||||
{ &m_testFilesPathArg, &m_applicationPathArg, &m_workingDirArg, &m_unitsArg, &m_parser.noColorArg(), &m_parser.helpArg() });
|
||||
|
||||
// parse arguments
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue