Create a fully functioning command line interface with 1.5 lines of code
github.com
github.com
That's what this is about.
int fired_main(int x = fire::arg("-x"), int y = fire::arg("-y"))
could just be int fired_main(int fire_arg(x), int fire_arg(y))
with something like #define fire_arg(v) v = fire::arg("-"#v)
The C preprocessor is still the thing I miss most when working in any other language. FIRE(args) {
// ...
}
without the explicit registration step. Unfortunately in this case the macro FIRE should first declare the fired function, then main, then defined the fired function, and this would be problematic because the definition can't have the default values for arguments again. I can't see a way around that.Click uses decorators though. I don’t know what the C++ equivalent could be.
https://github.com/c-blake/cligen achieves the actual 1-line of code dream without extra annotations and even leveraging existing API documentation and even colorizing said rST docs in terminal generated help output. { Of course, that one line might be an "import cligen; dispatch(foo)" which is arguably denser than most people would format it. } One usually wants to add some per-parameter help, though, unless your parameter names are always much more descriptive than "x" and "y".
Its purely marketing math, I think.
The definition of the function fired_main is similar to the definition of the function main, so it is not an extra line that is needed. But about half of the line deal with describing the command line arguments.