Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

int variables are always parsed as booleans #62

Open
Dadoum opened this issue Nov 28, 2023 · 0 comments
Open

int variables are always parsed as booleans #62

Dadoum opened this issue Nov 28, 2023 · 0 comments

Comments

@Dadoum
Copy link

Dadoum commented Nov 28, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant