DEXPRO-Solutions-GmbH / pdftools

PDF utility wrapping PDFBox
MIT License
0 stars 0 forks source link

Add top-level --version flag #7

Open fabiante opened 1 year ago

fabiante commented 1 year ago

Having an option to call java -jar pdftools.jar --version would be nice to figure out what version of the tool is installed.

Currently CLI users can not use such a command to figure out what version of this tool is installed.

fabiante commented 1 year ago

This may be helpful: https://picocli.info/#_dynamic_version_information

I guess that this requires somehow getting the version from the manifest / jar metadata and returning it via the documented interface.

fabiante commented 1 year ago

A couple of sources I skimmed through:

Implementing the required interface is kind of easy:

package one.squeeze.pdftools.cli;

import picocli.CommandLine;

/**
 * Provides a version for CLI commands based on the manifests implementation version.
 */
public class ManifestVersionProvider implements CommandLine.IVersionProvider {
    @Override
    public String[] getVersion() throws Exception {
        return new String[]{
            "some version" + this.getClass().getPackage().getImplementationVersion()
        };
    }
}

My problem with this is, that using this provider on the root command does not seem to work. I don't know why.