mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
parent
9d66976421
commit
dc74051832
24
README.md
24
README.md
@ -58,7 +58,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +161,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ The square of 4 is 16
|
|||||||
|
|
||||||
### Printing Help
|
### 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
|
$ ./main --help
|
||||||
@ -235,6 +235,8 @@ Optional arguments:
|
|||||||
-v, --verbose enable verbose logging
|
-v, --verbose enable verbose logging
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You may also get the help message in string via `program.help().str()`.
|
||||||
|
|
||||||
### List of Arguments
|
### 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.
|
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) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +282,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +314,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -388,7 +390,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +426,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,7 +468,7 @@ try {
|
|||||||
}
|
}
|
||||||
catch (const std::runtime_error& err) {
|
catch (const std::runtime_error& err) {
|
||||||
std::cout << err.what() << std::endl;
|
std::cout << err.what() << std::endl;
|
||||||
program.print_help();
|
std::cout << program;
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -458,7 +458,8 @@ public:
|
|||||||
|
|
||||||
// Printing the one and only help message
|
// Printing the one and only help message
|
||||||
// I've stuck with a simple message format, nothing fancy.
|
// 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();
|
auto out = help();
|
||||||
std::cout << out.rdbuf();
|
std::cout << out.rdbuf();
|
||||||
return out.str();
|
return out.str();
|
||||||
|
Loading…
Reference in New Issue
Block a user