本文整理汇总了C++中Arguments::addArgument方法的典型用法代码示例。如果您正苦于以下问题:C++ Arguments::addArgument方法的具体用法?C++ Arguments::addArgument怎么用?C++ Arguments::addArgument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arguments
的用法示例。
在下文中一共展示了Arguments::addArgument方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CORRADE_COMPARE
void ArgumentsTest::prefixedHelpWithoutPrefix() {
Arguments args;
args.addArgument("file").setHelp("file", "file to read")
.addBooleanOption('b', "binary").setHelp("binary", "read as binary")
.addSkippedPrefix("read", "reader options")
.addSkippedPrefix("write");
const auto expected = R"text(Usage:
./app [--read-...] [--write-...] [-h|--help] [-b|--binary] [--] file
Arguments:
file file to read
-h, --help display this help message and exit
-b, --binary read as binary
--read-... reader options
(see --read-help for details)
--write-... (see --write-help for details)
)text";
CORRADE_COMPARE(args.help(), expected);
}
void ArgumentsTest::prefixedHelpWithPrefix() {
Arguments args{"read"};
args.addOption("behavior", "buffered").setHelp("behavior", "reader behavior")
.addOption("buffer-size").setHelp("buffer-size", "buffer size", "SIZE");
const auto expected = R"text(Usage:
./app [--read-help] [--read-behavior BEHAVIOR] [--read-buffer-size SIZE] ...
Arguments:
... main application arguments
(see -h or --help for details)
--read-help display this help message and exit
--read-behavior BEHAVIOR reader behavior
(default: buffered)
--read-buffer-size SIZE buffer size
)text";
CORRADE_COMPARE(args.help(), expected);
}
void ArgumentsTest::prefixedDisallowedCalls() {
std::ostringstream out;
Error redirectError{&out};
Arguments args{"reader"};
args.addArgument("foo")
.addNamedArgument("bar")
.addOption('a', "baz")
.addBooleanOption("eh")
.setHelp("global help");
CORRADE_COMPARE(out.str(),
"Utility::Arguments::addArgument(): argument foo not allowed in prefixed version\n"
"Utility::Arguments::addNamedArgument(): argument bar not allowed in prefixed version\n"
"Utility::Arguments::addOption(): short option a not allowed in prefixed version\n"
"Utility::Arguments::addBooleanOption(): boolean option eh not allowed in prefixed version\n"
"Utility::Arguments::setHelp(): global help text only allowed in unprefixed version\n");
}
示例2: parseMissingArgument
void ArgumentsTest::parseMissingArgument() {
Arguments args;
args.addArgument("file").setHelp("file", "", "file.dat");
const char* argv[] = { "" };
const int argc = std::extent<decltype(argv)>();
std::ostringstream out;
Error redirectError{&out};
CORRADE_VERIFY(!args.tryParse(argc, argv));
CORRADE_COMPARE(out.str(), "Missing command-line argument file.dat\n");
}
示例3: parseArguments
void ArgumentsTest::parseArguments() {
Arguments args;
args.addArgument("name")
.addArgument("input")
.addArgument("output");
const char* argv[] = { "", "hello", "in.txt", "out.bin" };
const int argc = std::extent<decltype(argv)>();
CORRADE_VERIFY(args.tryParse(argc, argv));
CORRADE_COMPARE(args.value("name"), "hello");
CORRADE_COMPARE(args.value("input"), "in.txt");
CORRADE_COMPARE(args.value("output"), "out.bin");
}
示例4: parseMixed
void ArgumentsTest::parseMixed() {
Arguments args;
args.addArgument("file")
.addNamedArgument('o', "output")
.addOption("size", "56")
.addBooleanOption('v', "verbose")
.addBooleanOption('l', "loud");
const char* argv[] = { "", "-o", "log.txt", "-v", "input.txt" };
const int argc = std::extent<decltype(argv)>();
CORRADE_VERIFY(args.tryParse(argc, argv));
CORRADE_VERIFY(!args.isSet("help"));
CORRADE_VERIFY(args.isSet("verbose"));
CORRADE_COMPARE(args.value("file"), "input.txt");
/* Default values */
CORRADE_COMPARE(args.value("size"), "56");
CORRADE_VERIFY(!args.isSet("loud"));
}
示例5: BuildArgument
static void BuildArgument(
char const * const iValue,
Arguments & ioArguments)
{
ioArguments.addArgument(iValue);
}