add help to example1

This commit is contained in:
Carl Pearson
2020-05-07 07:34:37 -05:00
parent 661d569657
commit 73e1d1a71a
2 changed files with 16 additions and 2 deletions

View File

@@ -28,7 +28,8 @@ int main(int argc, char **argv) {
// from string.
// An option invoked with `--repeat N`
p.add_option(repeats, "--repeat")->help("how many times to repeat first argument");
p.add_option(repeats, "--repeat")
->help("how many times to repeat first argument");
// A flag invoked with `--verbose` or `-v`
p.add_flag(verbose, "--verbose", "-v");
// a required positional argument (position 1)
@@ -42,6 +43,12 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
// If help was requested, print it
if (p.need_help()) {
std::cerr << p.help();
return 0;
}
// Execute the program logic
if (verbose) {
std::cerr << "about to print '" << toPrint << "' " << repeats << " times";

View File

@@ -15,7 +15,8 @@ int main(int argc, char **argv) {
// from string.
// An option invoked with `--repeat N`
p.add_option(repeats, "--repeat")->help("how many times to repeat first argument");
p.add_option(repeats, "--repeat")
->help("how many times to repeat first argument");
// A flag invoked with `--verbose` or `-v`
p.add_flag(verbose, "--verbose", "-v");
// a required positional argument (position 1)
@@ -29,6 +30,12 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
// If help was requested, print it
if (p.need_help()) {
std::cerr << p.help();
return 0;
}
// Execute the program logic
if (verbose) {
std::cerr << "about to print '" << toPrint << "' " << repeats << " times";