mirror of
https://github.com/KeqingMoe/argparse.git
synced 2025-07-04 15:14:39 +00:00
Update README.md
This commit is contained in:
parent
4953ba7d76
commit
d09fb9af99
23
README.md
23
README.md
@ -127,11 +127,32 @@ program.add_argument("--input_files")
|
|||||||
.help("The list of input files")
|
.help("The list of input files")
|
||||||
.nargs(2);
|
.nargs(2);
|
||||||
|
|
||||||
program.parse_args({"./main", "--input_files", "config.yml", "System.xml"});
|
program.parse_args(argc, argv); // Example: ./main --input_files config.yml System.xml
|
||||||
|
|
||||||
auto files = program.get<std::vector<std::string>>("--input_files"); // {"config.yml", "System.xml"}
|
auto files = program.get<std::vector<std::string>>("--input_files"); // {"config.yml", "System.xml"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
```ArgumentParser.get<T>()``` has specializations for ```std::vector``` and ```std::list```. So, the following variant, ```.get<std::list>```, will also work.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
auto files = program.get<std::list<std::string>>("--input_files"); // Works! files now has {"config.yml", "System.xml"}
|
||||||
|
```
|
||||||
|
|
||||||
|
Using ```.action```, one can quickly build a list of custom objects from command line arguments. Here's an example:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
argparse::ArgumentParser program("main");
|
||||||
|
|
||||||
|
program.add_argument("--query_point")
|
||||||
|
.help("3D query point")
|
||||||
|
.nargs(3)
|
||||||
|
.action([](const std::string& value) { return std::stod(value); });
|
||||||
|
|
||||||
|
program.parse_args(argc, argv); // Example: ./main --query_point 3.5 4.7 9.2
|
||||||
|
|
||||||
|
auto query_point = program.get<std::vector<double>>("--query_point"); // {3.5, 4.7, 9.2}
|
||||||
|
```
|
||||||
|
|
||||||
### Compound Arguments
|
### Compound Arguments
|
||||||
|
|
||||||
Compound arguments are optional arguments that are combined and provided as a single argument. Example: ```ps -aux```
|
Compound arguments are optional arguments that are combined and provided as a single argument. Example: ```ps -aux```
|
||||||
|
Loading…
Reference in New Issue
Block a user