1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-05-03 14:03:52 +00:00

Adding test and better positional help output

This commit is contained in:
Henry Fredrick Schreiner 2017-03-15 08:54:31 -04:00
parent 0ca8a43ebd
commit 6d445ff03d
2 changed files with 37 additions and 2 deletions

View File

@ -312,8 +312,8 @@ public:
/// The name and any extras needed for positionals
std::string help_positional() const {
std::string out = pname_;
if(get_expected()<1)
out = out + "x" + std::to_string(get_expected());
if(get_expected()>1)
out = out + "(" + std::to_string(get_expected()) + "x)";
else if(get_expected()==-1)
out = out + "...";
out = get_required() ? out : "["+out+"]";

View File

@ -93,6 +93,41 @@ TEST(THelp, RequiredPositionalAndOptions) {
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS] something"));
}
TEST(THelp, MultiOpts) {
CLI::App app{"My prog"};
std::vector<int> x, y;
app.add_option("-q,--quick", x, "Disc")->expected(2);
app.add_option("-v,--vals", y, "Other");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, Not(HasSubstr("Positionals:")));
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS]"));
EXPECT_THAT(help, HasSubstr("INT x 2"));
EXPECT_THAT(help, HasSubstr("INT ..."));
}
TEST(THelp, MultiPosOpts) {
CLI::App app{"My prog"};
std::vector<int> x, y;
app.add_option("quick", x, "Disc")->expected(2);
app.add_option("vals", y, "Other");
std::string help = app.help();
EXPECT_THAT(help, HasSubstr("My prog"));
EXPECT_THAT(help, HasSubstr("Positionals:"));
EXPECT_THAT(help, HasSubstr("Usage: program [OPTIONS]"));
EXPECT_THAT(help, HasSubstr("INT x 2"));
EXPECT_THAT(help, HasSubstr("INT ..."));
EXPECT_THAT(help, HasSubstr("[quick(2x)]"));
EXPECT_THAT(help, HasSubstr("[vals...]"));
}
TEST(THelp, EnvName) {
CLI::App app{"My prog"};
std::string input;