From dc74051832a402e9069ed919223d0e1e63f88a99 Mon Sep 17 00:00:00 2001 From: Zhihao Yuan Date: Wed, 13 Nov 2019 02:28:37 -0600 Subject: [PATCH] Deprecate print_help() closes: p-ranav/argparse#40 --- README.md | 24 +++++++++++++----------- include/argparse.hpp | 3 ++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 00b5c7a..62dbb65 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -100,7 +100,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -161,7 +161,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -194,7 +194,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -221,7 +221,7 @@ The square of 4 is 16 ### Printing Help -```ArgumentParser.print_help()``` print a help message, including the program usage and information about the arguments registered with the ArgumentParser. For the previous example, here's the default help message: +`std::cout << program` prints a help message, including the program usage and information about the arguments registered with the `ArgumentParser`. For the previous example, here's the default help message: ``` $ ./main --help @@ -235,6 +235,8 @@ Optional arguments: -v, --verbose enable verbose logging ``` +You may also get the help message in string via `program.help().str()`. + ### List of Arguments ArgumentParser objects usually associate a single command-line argument with a single action to be taken. The ```.nargs``` associates a different number of command-line arguments with a single action. When using ```nargs(N)```, N arguments from the command line will be gathered together into a list. @@ -251,7 +253,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -280,7 +282,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -312,7 +314,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -388,7 +390,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -424,7 +426,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } @@ -466,7 +468,7 @@ try { } catch (const std::runtime_error& err) { std::cout << err.what() << std::endl; - program.print_help(); + std::cout << program; exit(0); } diff --git a/include/argparse.hpp b/include/argparse.hpp index 0b3410a..02aa6f6 100644 --- a/include/argparse.hpp +++ b/include/argparse.hpp @@ -458,7 +458,8 @@ public: // Printing the one and only help message // I've stuck with a simple message format, nothing fancy. - std::string print_help() { + [[deprecated("Use cout << program; instead. See also help().")]] std::string + print_help() { auto out = help(); std::cout << out.rdbuf(); return out.str();