On 22-Jun-2015 22:21, Alex Parrill wrote:
On Monday, 22 June 2015 at 19:09:40 UTC, weaselcat wrote:
I never seem to use them for anything, has anyone else done anything
interesting with them?
I'm writing a program that can accept subcommands via either the command
line (ex. `prog mycmd 1 2`) or via a shell. I represent each command as
a function, use UDAs to store the help text and if they can be ran from
the command line or shell. The command list, full help text, and command
dispatcher is generated at compile time via templates, CTFE, and static
foreach.
And I thought that I might be the only one doing this ;)
Declarative command-line handling is much more scalable approach for
swiss-army knife command-line tools.
An example command:
@("<nanoseconds>") // arguments
@("Sets the amount of time to increment the clock on each frame.") //
description
@ShellOnly // can't be ran from command line
int cmd_set_time_per_frame(string[] args) {
// ...
}
Awesome. Is it open-sourced?
How about handling argument conversion automatically (via to! and/or
custom functions)?
Say :
@("<num1> <num2>")
@CmdName("plus")
void add(int a, int b)
{
writelen(a+b);
}
To be automagically callable like:
./prog plus 2 4
--
Dmitry Olshansky