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

[Ideas] Custom ArgGroup Validation/Rules #1411

Closed
sbernard31 opened this issue Aug 13, 2021 · 3 comments
Closed

[Ideas] Custom ArgGroup Validation/Rules #1411

sbernard31 opened this issue Aug 13, 2021 · 3 comments

Comments

@sbernard31
Copy link
Contributor

Maybe I'm wrong but for now I didn't find a good way to use ArgGroup to make complex rules about options combination.
This is quickly verbose and/or we face some corner case issue. (see #1409)

So the idea would be to be able to group some options together in a ArgGroup for which validation is done manually. (see #1410)
But validation is not enough, you also need a custom synopsis as the default one will maybe no respect the rule you implement in your custom validation.

If I get it correctly, currently this is possible to propose a custom synopsis but only at Command level.
But I have some simple option where I would like to keep default display I just want to customize the ArgGroup one and see it added in the Command one.


(Not direclty linked maybe it need a dedicated issue)
In the ArgGroup heading I sometime want to display the ArgGroup synopsis and currently it is needed to maintain it manually maybe it could make sense to have a kind of marker like ${SYNOPSIS}.
Here some example of an ArgGroup help usage (not the complete help usage) where I want to display the ArgGroup synopsis:

X509 Options

By default Leshan demo uses an embedded self-signed certificate and trusts any 
client certificates allowing to use RPK or X509 at client side.
To use X509 with your own server key, certificate and truststore : 
     [-xcert, -xprik], [-truststore] should be used together.

      -xprik, --x509-private-key=<prik>
               The path to your server private key file
               The private key should be in PKCS#8 format (DER encoding).
      -xcert, --x509-certificate-chain=<certChain>
               The path to your server certificate or certificate chain file.
               The certificate Common Name (CN) should generally be equal to
                 the server hostname.
               The certificate should be in X509v3 format (DER or PEM encoding).
               The certificate chain should be in X509v3 format (PEM encoding).
      -ts, --truststore=<truststore>
               The path to  :
                - a root certificate file to trust,
                - OR a folder containing trusted certificates,
                - OR trust store URI.

               Certificates must be in in X509v3 format (DER encoding)
@remkop
Copy link
Owner

remkop commented Aug 14, 2021

The ArgGroup implementation is pretty complex and I am fairly happy with what it can do now, not planning to enhance this area in the near future.

I am not sure, can you achieve your requirements, using the current version of picocli, with some workaround?

@sbernard31
Copy link
Contributor Author

The ArgGroup implementation is pretty complex and I am fairly happy with what it can do now, not planning to enhance this area in the near future.

I'm not sure if you get me correctly, but the idea is not to allow more complex rules but instead to make possible to do your own complex rules manually (so hoping to avoid to make ArgGroup more complex). This already almost doable but some details can not be done (or done "properly")

I am not sure, can you achieve your requirements, using the current version of picocli, with some workaround?

  1. For the validation, I have a workaround. I create my own validate method and I need to call it manually in the @Command.run() methods. ( instead of a more elegant [ideas] MultiOption Validation #1410 but it's OK)

  2. For custom synopsis of my ArgGroup, I didn't find a workaround so the synopsis is incorrect.

  3. For ${SYNOPSIS}, I need to write it manually in the ArgGroup heading and without color for now. (so I have a workaround)

  4. For colored synopsis, I guess I could write it with color manually too (So I have a workaround) but it will not use the ColorScheme automatically. For this, I would need to be able to use some kind of predefined style like:

"@|option --myOption|@=@|underline Options|@|optionParams <optionvalue>|@",

In by default @|option = Style.fg_yellow and, @|optionParams = Style.italic.

@remkop
Copy link
Owner

remkop commented Feb 15, 2022

The synopsis problems (#964 #1408 #1574 ) should be resolved in the next release.

As for validation, I don't plan on providing picocli API for this.

Very good discussions though, thank you so much! 🙏

@remkop remkop closed this as completed Feb 15, 2022
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