Show HN: Add a command-line interface to any C++ program
github.com
github.com
class Arithmetic : public CommandInterface {
int add(int x, int y) {
return x + y;
}
void register_commands() override {
register_command(&Arithmetic::add, "add", "Add two numbers");
}
};
Simply evaluate a string to invoke the function. Arithmetic arithmetic;
arithmetic.eval("add 3 4"); // returns "7"
The user can place the eval() call behind any interface that has a string for its input and output. I personally use it behind a TCP socket on my trading application; I can query my strategy's state and change its parameters on the fly.If funky C++ interests you, the prop firm I work for is looking to hire engineers. Feel free to contact me directly: chris -AT- chrisaycock -DOT- com
If I understand the design correctly, one can provide a custom argument parser by specializing lexical_cast?
Personally I dislike conan, because package managers should be written in the language of the community they serve, but that is me.
Thankfully, both support binary libraries.
Then there are modules, which on Visual C++'s case are going along quite well.
Anyone that bothers using header only libraries only has themselves to blame for waiting for builds, they are a plague from users that pretend C and C++ are scripting languages.
Header-only libraries can give substantial speedups (25% in extreme cases).
I really would like to see benchmarks versus proper use of binary libraries.
I shouldn't have to think about it; I shouldn't have to explicitly opt-out to have privacy. Telemetry should always be opt-in, and not opted-in by default.
Slow-compiling APIs can be made in any form, whether "header only" or not. C++ template APIs cannot be compiled separately and can cause long compile times for all transitively dependent translation units.
For example, stb_image.h is a single file that is 1 copy+paste from github away. It compiles quite quickly, and often you will need it alongside only a single .c file in your project, but anyway it's extremely easy to compile it separately. All you have to do is cut+paste the implementation part to a separate .c file.
Also modules support templates just fine.
Indeed, header only libs are just doing PHP like programming.
But, what I really, really wish caught on would be "single cpp file" with the expectation that you are capable of adding a single, self-contained source file to whatever build system you happen to be using.
My library is for single-name commands that can take simple parameters. You can't define your own language here.
Saying as someone who worked on a cli framework for network devices in the past and quite enjoyed it. It was in C though, so it wasn't as terse.
However I think Genopt is concerned with command line arguments.
This is about an interactive command line interface, like a REPL. So you type command and it calls functions interactivly.
This kind of thing can be a lot of work to do right, so I think this header looks great. I'm looking forward to trying it out.
https://www.boost.org/doc/libs/1_77_0/doc/html/program_optio...
Nonetheless I prefer to use cxxopts[0] over BPO if I can justify the extra submodule