You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-54Lines changed: 34 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,62 +20,52 @@ The goals of this library, in order of importance, are:
20
20
It's also very closely related to the previous goal.
21
21
We should be able to detect most errors at compile-time and provide decent diagnostics.
22
22
23
-
1.**_Try_ not to repeat yourself.**
23
+
1.**Don't repeat yourself.**
24
24
25
-
When specifying a CLI, if some information was already given to the library, that same information should not be needed again.
26
-
For example, if the type of an argument was already specified, the user should not be asked to tell the type again.
27
-
Unfortunately that is very hard, so some places still require duplicate information.
25
+
When specifying the CLI, if some information was already given to the library, that same information should not be needed again.
26
+
For example, the type of an argument is always known during setup, so the user should not be asked to inform the type when querying that argument.
28
27
29
28
1.**Be bleeding-edge.**
30
29
31
-
This library requires C++20.
32
-
That limits a lot its potential users, but also allows for the use of the new and powerful features of C++.
30
+
This isn't really a goal, but a fact: this library requires C++23.
31
+
That limits a lot its potential users (so there are plans to at least go back to C++20),
32
+
but also allows for the use of the new and powerful features of C++.
33
33
It also helps to accomplish the previous goals.
34
34
35
35
## Disclaimer
36
36
37
37
- This is a **personal project** with **no promise of maintainability** for the time being.
38
38
39
-
I started it to learn more about C++ and its new features.
39
+
- I have just rewritten the entire library, so **it is neither stable nor production-ready**.
40
40
41
-
- Although it is *not* in *early* development, since I'm working on it for months and iterated over it many times,
42
-
**it is not stable or production-ready**.
43
-
44
-
- There are **many unit tests missing**.
45
-
46
-
- I frequently changed the interface of the library and I'm **not afraid of changing it radically again** if I think it would improve the UX.
47
-
48
-
Another example is the names of the `namespaces` and what is in them.
41
+
- There are **no unit tests** (since the rewrite).
49
42
50
43
- There is *a lot* of polish and optimization work to do.
51
44
52
45
- There is a whole documentation to write.
53
46
54
47
## Sneak peek
55
48
56
-
The code below is a fully working example, taken from [`examples/hello.cpp`][examples/hello], only reformatted and with quotes changed to angle brackets in the `#include`.
49
+
The code below is a fully working example, taken from [`examples/hello.cpp`](examples/hello.cpp),
50
+
only with quotes changed to angle brackets in the `#include`.
57
51
Feel free to take a look at the other, more complex, examples in the same directory.
58
52
59
53
```cpp
60
-
#include<iostream>
61
-
#include<string_view>
54
+
#include<print>
55
+
#include<variant>
62
56
63
-
#include<opzioni.hpp>
57
+
#include<opzioni/all.hpp>
64
58
65
59
intmain(int argc, char const *argv[]) {
66
-
using namespace opzioni;
67
-
68
-
constexpr auto hello =
69
-
Program("hello")
70
-
.version("0.1")
71
-
.intro("Greeting people since the dawn of computing")
72
-
.add(Pos("name").help("Your name please, so I can greet you"))
73
-
.add(Help())
74
-
.add(Version());
75
-
76
-
auto const args = hello(argc, argv);
77
-
std::string_view const name = args["name"];
78
-
std::cout << "Hello, " << name << "!\n";
60
+
auto hello_cmd = opz::new_cmd("hello", "1.0")
61
+
.intro("Greeting people since the dawn of computing")
62
+
.pos<"name">({.help = "Your name please, so I can greet you"})
63
+
.flg<"help", "h">(opz::default_help)
64
+
.flg<"version", "v">(opz::default_version);
65
+
66
+
auto const map = opz::parse(hello_cmd, argc, argv);
67
+
auto const name = map.get<"name">();
68
+
std::print("Hello, {}!\n", name);
79
69
}
80
70
```
81
71
@@ -85,36 +75,33 @@ That gives us:
85
75
86
76
```
87
77
$ ./build/examples/hello -h
88
-
hello 0.1
78
+
hello 1.0
89
79
90
80
Greeting people since the dawn of computing
91
81
92
82
Usage:
93
83
hello <name> [--help] [--version]
94
-
84
+
95
85
Positionals:
96
86
name Your name please, so I can greet you
97
87
98
88
Options & Flags:
99
89
-h, --help Display this information
100
-
-V, --version Display the software version
90
+
-v, --version Display hello's version
101
91
```
102
92
103
-
1. Automatic version with `--version` or `-V`
93
+
1. Automatic version with `--version` or `-v`
104
94
105
95
```
106
-
$ ./build/examples/hello -V
107
-
hello 0.1
96
+
$ ./build/examples/hello -v
97
+
hello 1.0
108
98
```
109
99
110
-
1. Automatic error handling
100
+
1. Automatic error handling (_WIP_)
111
101
112
102
```
113
103
$ ./build/examples/hello Gabriel Galli
114
-
Unexpected positional argument `Galli`. This program expects 1 positional arguments
115
-
116
-
Usage:
117
-
hello <name> [--help] [--version]
104
+
libc++abi: terminating due to uncaught exception of type opz::UnexpectedPositional: Unexpected positional argument for `hello`: `Galli` (1 are expected)
118
105
```
119
106
120
107
1. And finally:
@@ -131,8 +118,9 @@ Meanwhile, it is kinda straightforward to build it locally, since just a simple
131
118
The build system is the awesome [Meson](https://mesonbuild.com/).
132
119
133
120
1. Download and install conda if you haven't already.
134
-
Just grab a suitable installer from [here](https://docs.conda.io/en/latest/miniconda.html) and run it.
135
-
There's also an install guide [here](https://conda.io/projects/conda/en/latest/user-guide/install/index.html).
121
+
122
+
You can either use [miniforge](https://conda-forge.org) (recommended, personally),
123
+
or [miniconda](https://www.anaconda.com/docs/getting-started/miniconda/main).
136
124
137
125
1. Clone this repository:
138
126
@@ -163,7 +151,7 @@ Feel free to inspect it and not use it.
163
151
164
152
## License
165
153
166
-
opzioni's license is the [Boost Software License (BSL) 1.0][license].
154
+
opzioni's license is the [Boost Software License (BSL) 1.0](LICENSE).
167
155
168
156
This means you are **free to use** this library **as you wish** and see fit.
169
157
@@ -176,11 +164,3 @@ In other words, **there is no need to bundle opzioni's license with your binary*
Thank you to [JetBrains](https://www.jetbrains.com/?from=opzioni) for supporting this project by providing free access to its products as part of the Open Source Licenses program.
0 commit comments