Skip to content

Commit ab8ca80

Browse files
README.md: add install section & formatting
1 parent 6460bd6 commit ab8ca80

File tree

1 file changed

+64
-28
lines changed

1 file changed

+64
-28
lines changed

README.md

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This simple header-only library allows you to easily define, parse and examine
44
program options and positional parameters in a C++ program. :notes:
55

6-
Here is a super simple example of how to use **pgm::args**:
6+
Here is a very simple example of how to use **pgm::args**:
77

88
```cpp
99
// example1.cpp
@@ -23,7 +23,7 @@ int main(int argc, char* argv[])
2323

2424
if (args["--version"])
2525
{
26-
std::cout << argv[0] << " 0.42" << std::endl;
26+
std::cout << argv[0] << " version " << 0.42 << std::endl;
2727
return 0;
2828
}
2929
if (args["--help"])
@@ -52,11 +52,39 @@ Options:
5252
-h, --help Show this help screen and exit.
5353
5454
user@linux:~$ ./example1 -v
55-
./example1 0.42
55+
./example1 version 0.42
5656
5757
user@linux:~$
5858
```
5959

60+
## Installing pgm::args
61+
62+
You can install **`pgm::args`** in one of the following ways:
63+
64+
1. Install binary package, if you are on Debian/Ubuntu/etc:
65+
66+
```console
67+
$ v=0.2 p=libpgm-args-dev_${v}_all.deb
68+
$ wget https://github.com/dimitry-ishenko-cpp/pgm-args/releases/download/v${v}/${p}
69+
$ sudo apt install ./${p}
70+
```
71+
72+
2. Install from source:
73+
74+
```console
75+
$ mkdir build
76+
$ cd build
77+
$ cmake ..
78+
$ make all test
79+
$ sudo make install
80+
```
81+
82+
3. Add as a sub-module to your project:
83+
84+
```console
85+
$ git submodule add https://github.com/dimitry-ishenko-cpp/pgm-args.git pgm
86+
```
87+
6088
## Using pgm::args
6189

6290
### :zero: Understand the Nomenclature
@@ -71,7 +99,7 @@ user@linux:~$ foo bar baz
7199
`foo` is the program, and `bar` and `baz` are the _arguments_. Following rules
72100
apply to program arguments:
73101

74-
:key: Arguments beginning with the hyphen (`-`) delimiter are called _options_.
102+
:key: Arguments beginning with the hyphen delimiter `-` are called _options_.
75103

76104
:key: There are two kinds of options:
77105

@@ -113,7 +141,7 @@ foo --output=path
113141
foo --output path
114142
```
115143

116-
_NOTE:_ the equal sign (`=`) delimiter between the option and its value.
144+
Note the equal sign `=` delimiter between the option and its value.
117145

118146
:key: Options typically precede other non-option arguments, which are called
119147
_positional parameters_.
@@ -127,10 +155,10 @@ foo -a --bar baz -- -c --qux
127155
```
128156

129157
`-a` and `--bar` are treated as options, and `baz`, `-c` and `--qux` are treated
130-
as positional parameters (unless `--bar` requires a value, in which case `baz`
131-
will be treated as an option value).
158+
as positional parameters (unless option `--bar` requires a value, in which case
159+
`baz` will be treated as an option value).
132160

133-
:key: A token consisting of a single hyphen (`-`) is treated as an ordinary
161+
:key: A token consisting of a single hyphen `-` is treated as an ordinary
134162
non-option argument.
135163

136164
---
@@ -172,9 +200,9 @@ followed by one
172200
character, eg:
173201
174202
```cpp
175-
pgm::arg{ "-a", "..." }; // (1)
176-
pgm::arg{ "-b", "..." }; // (1)
177-
pgm::arg{ "-c", "..." }; // (1)
203+
pgm::arg{ "-a", "..." }; // (1)
204+
pgm::arg{ "-b", "..." }; // (1)
205+
pgm::arg{ "-c", "..." }; // (1)
178206
```
179207

180208
:rose: **`long_name`** is a long option name consisting of two hyphens followed
@@ -194,22 +222,22 @@ pgm::arg{ "-v", "--version", "..." }; // (4)
194222
[graphic](https://en.cppreference.com/w/cpp/string/byte/isgraph) characters, eg:
195223
196224
```cpp
197-
pgm::arg{ "source", "..." }; // (3)
198-
pgm::arg{ "x+y", "..." }; // (3)
199-
pgm::arg{ "foo/bar/baz", "..." }; // (3)
225+
pgm::arg{ "source", "..." }; // (3)
226+
pgm::arg{ "x+y", "..." }; // (3)
227+
pgm::arg{ "foo/bar/baz", "..." }; // (3)
200228
```
201229

202230
:rose: **`value_name`** is an option value name that can contain any
203231
[graphic](https://en.cppreference.com/w/cpp/string/byte/isgraph) characters, eg:
204232

205233
```cpp
206-
pgm::arg{ "-i", "file-name", "..." }; // (5)
207-
pgm::arg{ "-l", "log-file", "..." }; // (5)
234+
pgm::arg{ "-i", "file-name", "..." }; // (5)
235+
pgm::arg{ "-l", "log-file", "..." }; // (5)
208236

209-
pgm::arg{ "--filter", "name", "..." }; // (6)
210-
pgm::arg{ "--set-time", "HH:MM", "..." }; // (6)
237+
pgm::arg{ "--filter", "name", "..." }; // (6)
238+
pgm::arg{ "--set-time", "HH:MM", "..." }; // (6)
211239

212-
pgm::arg{ "-w", "--wait", "time", "..." }; // (7)
240+
pgm::arg{ "-w", "--wait", "time", "..." }; // (7)
213241
pgm::arg{ "-d", "--debug", "level", "..." }; // (7)
214242
```
215243
@@ -225,7 +253,7 @@ pgm::arg{ "foo/bar/baz", "Lorem ipsum dolor sit amet." }; // (3)
225253
```
226254

227255
:rose: **`spec`** is an option/param specification consisting of one or more of
228-
the following flags combined using the vertical pipe (`|`) delimiter:
256+
the following flags combined using the vertical pipe `|` delimiter:
229257

230258
| flag | option | param | meaning |
231259
|:-----------------:|:------------------:|:------------------:|:--------|
@@ -354,7 +382,7 @@ The subscript `operator[]` returns const ref to an instance of
354382
```
355383

356384
`operator bool()` of **`pgm::argval`** is marked as explicit, so you may have
357-
to use `static_cast` or double logical negation (`!!`) to force boolean
385+
to use `static_cast` or double logical negation `!!` to force boolean
358386
context in certain situations, eg:
359387

360388
```cpp
@@ -369,8 +397,8 @@ The subscript `operator[]` returns const ref to an instance of
369397

370398
```cpp
371399
std::exception_ptr ep;
372-
try{ args.parse(argc, argv); }
373-
catch(...){ ep = std::current_exception(); }
400+
try { args.parse(argc, argv); }
401+
catch (...) { ep = std::current_exception(); }
374402

375403
if (args["--help"]) show_usage();
376404
else if (ep) std::rethrow_exception(ep);
@@ -467,6 +495,8 @@ Here is a more complete example of using **pgm::args**:
467495
void show_usage(const pgm::args& args, std::string_view name);
468496
void show_version(std::string_view name);
469497
498+
void transfer(std::string_view source, std::string_view dest);
499+
470500
int main(int argc, char* argv[])
471501
try
472502
{
@@ -492,8 +522,8 @@ try
492522
};
493523
494524
std::exception_ptr ep;
495-
try{ args.parse(argc, argv); }
496-
catch(...){ ep = std::current_exception(); }
525+
try { args.parse(argc, argv); }
526+
catch (...) { ep = std::current_exception(); }
497527
498528
if (args["--help"])
499529
show_usage(args, name);
@@ -529,9 +559,10 @@ try
529559
auto dest = args["DEST"].value();
530560
531561
// "transfer" files
532-
for(auto const& source : sources)
562+
for (auto const& source : sources)
533563
{
534-
if(!quiet) std::cout << "Sending " << source << " to " << dest << std::endl;
564+
if (!quiet) std::cout << "Sending " << source << " to " << dest << std::endl;
565+
transfer(source, dest);
535566
}
536567
}
537568
@@ -564,7 +595,12 @@ program, nothing will actually be transferred.)";
564595
565596
void show_version(std::string_view name)
566597
{
567-
std::cout << name << " 0.42" << std::endl;
598+
std::cout << name << " version " << 0.42 << std::endl;
599+
}
600+
601+
void transfer(std::string_view source, std::string_view dest)
602+
{
603+
//
568604
}
569605
```
570606

0 commit comments

Comments
 (0)