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

Flag type option (boolean type, no explicit value) for CLI #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Flag type option (boolean type, no explicit value) for CLI #31

wants to merge 1 commit into from

Conversation

NekoiNemo
Copy link

I would like to suggest adding flag type CLI argument support (that is set to true by its mere inclusion).
Similar to --help/-h

@Fleshgrinder
Copy link

👍 I really would love to see this merged @npryce


properties[configNameByOpt.configNameFor(opt)] = CommandLineProperty(arg, args[i])
if (i + 1 >= args.size || args[i+1].startsWith("-")) {
properties[configNameByOpt.configNameFor(opt)] = CommandLineProperty(arg, "true")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be confusing for non-boolean options. Is there a way to make this type-safe and work for booleans only?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, generalise it and make it work for any type? That way, it could work for enums as well as booleans.

For example: the CommandLineProperty class could have an optional (nullable) default value field. If it is non-null, that value is used when an explicit argument is not given.

An overload of the CommandLineProperty function for boolean keys could set the default value to true.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about providing a PR on my own for this and my solution would have been to introduce a CommandLineFlag class that is meant for exactly that. However, by now I think that the best solution would be to interpret every booleanType as a flag since nothing else makes sense.

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

Successfully merging this pull request may close these issues.

None yet

3 participants