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

Optional values #69

Open
AMythicDev opened this issue Dec 20, 2024 · 4 comments
Open

Optional values #69

AMythicDev opened this issue Dec 20, 2024 · 4 comments

Comments

@AMythicDev
Copy link

Currently there's no way to mark a ValueT as optional and the only possible workaround to this is to use a OptionT with a val field which limits the ergonomics on the CLI side. Having optional values can allow certain values to be passed directly without any prefix option.

@00JCIV00
Copy link
Owner

@AMythicDev You can accomplish this using the vals_mandatory field of a single Command, or the global_vals_mandatory in your Command Config for all Commands.

The limitation here is that the Values still need to be provided in order. So if you have two Values on a Command, like an integer and a string, you can do all of these:

cmd
cmd 10
cmd 10 "some string"

But you can not do:

cmd "some string"

Let me know if that works for you or if you have any other questions. Thanks for trying Cova!

@AMythicDev
Copy link
Author

Thanks, the vals_mandatory option did the trick. However I was wondering if we could do this on per value basis rather than for all values in a command. Like in a command I want some values to be required and some values to be optional.

We can enforce that all the required value fields to be the last in value order and will always be matched. If they don't match, we raise an error. For optional values, they must be present before all required values and they are matched after all required values are matched.

Let me know if you are interested in it and feel free to hit me if you want any help.

Thanks again for the speedy response.

@00JCIV00
Copy link
Owner

00JCIV00 commented Dec 20, 2024

That's doable, but it'd be a somewhat heavy change to the Value parsing. If I do implement it, I'll likely go with Mandatory Values first. Let me think about it a bit.

In the interim, you could try sequentially looking for your required Values immediately after calling cova.parse(). That could be done in just a few lines pretty easily. I can put together an example a little later if you'd like.

@AMythicDev
Copy link
Author

Thanks for looking into it. Will be happy to see it getting implemented.

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

2 participants