improve example
This commit is contained in:
11
README.md
11
README.md
@@ -28,11 +28,16 @@ int main(int argc, char **argv) {
|
|||||||
std::string maybePrint;
|
std::string maybePrint;
|
||||||
int repeats = 1;
|
int repeats = 1;
|
||||||
|
|
||||||
// Inform the parser of the program data.
|
// Inform the parser of the program data. It will do type-specific conversion
|
||||||
// It will do type-specific conversion
|
// from string.
|
||||||
|
|
||||||
|
// An option invoked with `--repeat N`
|
||||||
p.add_option(repeats, "--repeat");
|
p.add_option(repeats, "--repeat");
|
||||||
|
// A flag invoked with `--verbose` or `-v`
|
||||||
p.add_flag(verbose, "--verbose", "-v");
|
p.add_flag(verbose, "--verbose", "-v");
|
||||||
|
// a required positional argument (position 1)
|
||||||
p.add_positional(toPrint)->required();
|
p.add_positional(toPrint)->required();
|
||||||
|
// an optional positional argument (position 2)
|
||||||
auto psnl = p.add_positional(maybePrint);
|
auto psnl = p.add_positional(maybePrint);
|
||||||
|
|
||||||
// If there was an error during parsing, report it.
|
// If there was an error during parsing, report it.
|
||||||
@@ -45,7 +50,7 @@ int main(int argc, char **argv) {
|
|||||||
if (verbose) {
|
if (verbose) {
|
||||||
std::cerr << "about to print '" << toPrint << "' " << repeats << " times";
|
std::cerr << "about to print '" << toPrint << "' " << repeats << " times";
|
||||||
if (psnl->found()) {
|
if (psnl->found()) {
|
||||||
std::cerr << ", then '" << maybePrint << "'";
|
std::cerr << ", then '" << maybePrint << "'";
|
||||||
}
|
}
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
}
|
}
|
||||||
|
@@ -11,11 +11,16 @@ int main(int argc, char **argv) {
|
|||||||
std::string maybePrint;
|
std::string maybePrint;
|
||||||
int repeats = 1;
|
int repeats = 1;
|
||||||
|
|
||||||
// Inform the parser of the program data.
|
// Inform the parser of the program data. It will do type-specific conversion
|
||||||
// It will do type-specific conversion
|
// from string.
|
||||||
|
|
||||||
|
// An option invoked with `--repeat N`
|
||||||
p.add_option(repeats, "--repeat");
|
p.add_option(repeats, "--repeat");
|
||||||
|
// A flag invoked with `--verbose` or `-v`
|
||||||
p.add_flag(verbose, "--verbose", "-v");
|
p.add_flag(verbose, "--verbose", "-v");
|
||||||
|
// a required positional argument (position 1)
|
||||||
p.add_positional(toPrint)->required();
|
p.add_positional(toPrint)->required();
|
||||||
|
// an optional positional argument (position 2)
|
||||||
auto psnl = p.add_positional(maybePrint);
|
auto psnl = p.add_positional(maybePrint);
|
||||||
|
|
||||||
// If there was an error during parsing, report it.
|
// If there was an error during parsing, report it.
|
||||||
|
Reference in New Issue
Block a user