Show HN: Structopt for C++ – Parse command line arguments by defining a struct
github.com
github.com
In my opinion, it is _the_ way to quickly create a quality CLI.
I don't think this coincidence. This looks like it's directly inspired by the Rust library, even though the README gives no indication of that.
Though I'm not sure if the Rust clap has any origins in any specific library for another language.
The nice thing with Python is that I implemented a parser from a function signature, and it also works for NamedTuple.
The advantage wrt to other python parser is that it uses the type annotations, instead of guessing
It seems to have plenty of features and good documentation, plus it's available as a single header file.
Looks like everyone and their grandmum makes a command line parser. I can see the draw. It’s a problem with a small scope that you can make a dent in over a weekend.
I haven't touched C++ for almost a decade but I assume there's (still?) no obvious way that always works to include a dependency package in your build?
For you C++ devs, does this instruction make it obvious how to install this thing into your project?
(While it feels better than fighting the system to get a dependency to link properly I would still rather have a proper package manager...)
But in the end it all seems to come down to this single header file which only depends on C++ stdlib headers and which can be dropped into your own project (which seems to be generated (aka "amalgamated") from multiple smaller header files):
https://github.com/p-ranav/structopt/tree/master/single_incl...
So for typical C++ libraries, this seems quite straightforward to integrate. Usually when looking at a project directory full of random files like this, it's a lot more complicated.
* add the structopt repository as a git submodule to your project
* add something like `add_subdirectory(structopt)` to your top-level CMake script
* add structopt to your target_link_libraries
and you're good to go.
But given that it's a header-only library, you can also just download the files, put them in your repo somewhere, and #include them.
I much prefer this to manually downloading the files, even for header-only libraries. The command provided a nice declarative way of adding a dependency.
Most of the time, you'll want the latter. The right thing to do in 2020 in that case is IMHO to integrate with a source-based build system like vcpkg, portage (see the prefix project), conan, macports etc. Once the dev-env setup script boils down to just a list of packages, the question of importing third-party dependencies stops being a pain.
I've used most of these (except conan) and vcpkg seems like it's the most painless one, especially because it's a CMake-based system and FWIW CMake seems to be what the C++ world is converging on these days. From my bubble anyway.
The main problem was nuget support for C++ DLLs is pretty horrible. I did not want to resort to parsing the .targets file from CMake script so I ended up making non-standard nuget packages that pretty much only worked with our CMake script.
Now does it generate the synopsis part of a man page automatically?
The only legitimate case I've seen for C++ <17 is if you need to compile on MacOS <= 10.13 for shipping 32 bit binaries on Mac, where C++17 features are experimental in XCode (but I haven't had an issue with compatibility in C++17 supported compilers).
CentOS and Debian shipping ancient GCC versions isn't an excuse, it's trivial to update.
If only life was that simple.
But people delivering libraries to customers who have elected not to upgrade to current releases are pretty much stuck. It is extremely common for banks, in particular, to still be running gcc-4, and to have no plans ever to upgrade.
It is common at least in banks to have an unbreakable policy never to upgrade software on a server to a version that was not on it when it was unboxed. They may bend just so far as to install back-patched security fixes from the vendor. But a libstdc++.so compatible with a current language Standard? Haha, they say, you must be joking.
It is not unusual for them to still run RHEL 6, or even 5. Bloomberg infamously still has 32-bit SPARCs in the basement, running code compiled only ever with Sun's old compiler.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
brew install gcc@10
or https://github.com/fsquillace/junestare your friends
static VISIT_STRUCT_CONSTEXPR const int max_visitable_members = 69; https://github.com/p-ranav/structopt/blob/master/single_incl...
That looks like something that was proposed for inclusion in boost a long time ago. I think it eventually got accepted after some renaming :)
The amount of preprocessor magic in that file makes my head hurt.
It's an interesting concept where you define the command line "help" syntax and it generates an arguments structure and an associated parser. I've used the C version, I believe the C++ version is better maintained.
I maintain two ports of docopt and I'm telling you not to use it.
;-)