From 4dc61b679e972b48b6087215166a86e810955572 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sun, 31 Mar 2019 16:28:49 -0400 Subject: [PATCH 1/2] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86ce2dd..c3dead6 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,9 @@ program.add_argument("--verbose", "-v") program.parse_args({ "./main", "--verbose" }); -auto a = program.get("--verbose"); // true +if (program["--verbose'] == true) { // true + // enable verbose logging +} ``` ### Compound Arguments From 921e5ca7f4994cf3c2df4aa53d7b16b84f2912d3 Mon Sep 17 00:00:00 2001 From: Pranav Srinivas Kumar Date: Sun, 31 Mar 2019 16:58:18 -0400 Subject: [PATCH 2/2] Update README.md --- README.md | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3dead6..4f7aac0 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,54 @@ ## Highlights -* Simply include +* Header-only library * Requires C++17 * MIT License +## Quick Start + +Simply include argparse.hpp and you're good to go. + +```cpp +#include +``` + +To start parsing command-line arguments, create an ```ArgumentParser```. + +```cpp +argparse::ArgumentParser program("program name"); +``` + +Argparse supports a variety of argument types including: +* Positional arguments +* Optional arguments +* Toggle arguments +* Compound arguments + +Here's an example of a positional argument: + +```cpp +program.add_argument("square") + .help("display a square of a given number") + .action([](const std::string& value) { auto integer = std::stoi(value); return integer * integer; }); + +program.parse_args(argc, argv); +std::cout << program.get("square") << std::endl; +``` + +And running the code: + +```bash +$ ./main 15 +225 +``` + +Here's what's happening: + +* We’ve added the add_argument() method, which is what we use to specify which command-line options the program is willing to accept. In this case, I’ve named it square so that it’s in line with its function. +* Calling our program now requires us to specify an option. +* The parse_args() method parses the arguments provided and performs the user-defined action each time it visits an argument value. + ## Examples ### Positional Arguments