jcli
jcli copied to clipboard
int variables are always parsed as booleans
Version tested: 0.24.0. It seems to occur in all 0.20+ (I can't get 0.25 betas to parse anything at all).
DMD v2.102.1 and LDC2 v1.33.0, Linux (Fedora on x86_64).
import jcli;
@CommandDefault("Asserts that the given number is even.")
struct AssertEvenCommand
{
// Positional args are args that aren't defined by a command line flag.
//
// i.e. "mytool.exe abc 123" - 'abc' is the 0th positional arg, '123' is the 1st, etc.
@ArgPositional("number", "The number to assert.")
int number; // Conversions are performed via `ArgBinder`, which is a topic for a different example.
// Return either int or void. Use `int` if you want to control the exit code.
int onExecute()
{
auto passedAssert = this.number % 2 == 0;
return (passedAssert) ? 0 : 128; // 128 on error.
}
/++
+ EXAMPLE USAGE:
+ test.exe 20 -> status code 0
+ test.exe 21 -> status code 128
+ test.exe 20 --reverse -> status code 128
+ test.exe 21 --reverse -> status code 0
+ ++/
}
int main(string[] args)
{
auto cli = new CommandLineInterface!(app)();
return cli.parseAndExecute(args);
}
The executable compiles, but running it results in a parse failure, since it wants to parse a boolean value. When we put a boolean value it is then converted in an int.