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

Add more built-in converters #83

Closed
remkop opened this issue Apr 10, 2017 · 4 comments
Closed

Add more built-in converters #83

remkop opened this issue Apr 10, 2017 · 4 comments

Comments

@remkop
Copy link
Owner

remkop commented Apr 10, 2017

Gary has some good ideas. Picking Java 5-native types:

  • Currency
  • Locale
  • TimeZone
  • ByteOrder
  • Class
  • java.net.NetworkInterface
  • java.sql.Connection
  • java.sql.Driver
  • java.sql.Timestamp

Special care needed:

  • java.sql.Types - converts from String to int. Picocli may need to introduce a converter attribute on @Option and @Parameters to support the ability to have different converters on a per-field basis instead of just on a per-type basis.

Java 6 or higher (reflection?)

  • java.time.Duration
  • java.time.* (Duration, Instant, LocalDate, ... etc)
  • -PosixFilePermission- (enum, no special converter needed, will work out of the box)
  • java.nio.file.* (Path, FileSystem, LinkPermission)

Unsure

Unsure about some of the remaining converters; these types may not be used often...

Picocli makes registering custom converters much easier than JCommander. In JCommander one must specify a converter class name in the annotation, so an actual named class needs to be defined. In picocli, a single line lambda expression is sufficient. For example,

CommandLine cmd = new CommandLine(new SomeCommand());
cmd.registerConverter(MessageDigest.class, s -> MessageDigest.getInstance(s));

Given the above ease of use I'm not sure we need built-in converters for the below:

  • javax.xml.datatype.Duration
  • javax.xml.namespace.QName
  • javax.crypto.Cipher, javax.crypto.KeyGenerator, javax.crypto.Mac, javax.crypto.SecretKeyFactory
  • java.security.AlgorithmParameterGenerator, java.security.AlgorithmParameters, java.security.KeyFactory, java.security.KeyPairGenerator, java.security.KeyStore, java.security.MessageDigest, java.security.Signature
@remkop remkop added this to the 0.5.0 advanced option parsing milestone Apr 10, 2017
@garydgregory
Copy link

Note that Duration is a Java 8 class.

@garydgregory
Copy link

java.time.Duration that is.

@garydgregory
Copy link

Single (long) line or not, if I do it more than once, I will want to refactor it. My vote is for ease of use the first go around.

@garydgregory
Copy link

I would make Java 8 the min req and avoid reflection hacks.

@remkop remkop modified the milestones: backlog, 2.1.0 Oct 20, 2017
@remkop remkop modified the milestones: 2.1.0, 2.2.0 Nov 28, 2017
@remkop remkop modified the milestones: 3.0, 2.2.0 Dec 16, 2017
remkop added a commit that referenced this issue Dec 18, 2017
remkop added a commit that referenced this issue Dec 18, 2017
- #83 additional built-in type converters;
- #247 @ParentCommand annotation and general subcommand documentation
@remkop remkop closed this as completed in a9c41c0 Dec 19, 2017
remkop added a commit that referenced this issue Dec 19, 2017
Also reduced duplicate tracing for #83 reflective type converters.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants