jbang icon indicating copy to clipboard operation
jbang copied to clipboard

Know JBang version in custom JBang scripts or commands

Open davsclaus opened this issue 2 years ago • 6 comments

Is your feature request related to a problem? Please describe.

To know the jbang version at runtime in custom jbang app (eg camel-jbang)

Describe the solution you'd like A clear and concise description of what you want to happen.

I would like jbang to automatic set a JVM system property with the jbang version so I can find out without having to use any jbang API as I need this in a neutral way.

In my camel jbang commands then I only have dependency on picocli and therefore cannot use jbang JARs.

davsclaus avatar Aug 25 '22 14:08 davsclaus

That's not a bad idea. 👍

quintesse avatar Aug 25 '22 16:08 quintesse

Here is a sample what the Camel CLI we are working on

~/workspace ❯ camel get
  PID   NAME      CAMEL            PLATFORM  READY   STATE   AGE  TOTAL  FAILED  INFLIGHT  SINCE-LAST
 49448  bar.yaml  3.19.0-SNAPSHOT  JBang      1/1   Started   6s      3       0         0          0s

In the PLATFORM column I would like to say

JBang v0.97.0

davsclaus avatar Aug 25 '22 17:08 davsclaus

This would probably better to be environment variables rather than system properties to be consistent when using native built apps.

+1 on the feature.

maxandersen avatar Sep 01 '22 03:09 maxandersen

This would probably better to be environment variables rather than system properties

True, but I don't think we can actually do that. Or at least not easily. Because of the way we run the final code. On Linux and Mac we could generate a command line like JBANG_VERSION=1.2.3 java ...... but that won't work on Windows. We'd need multi-line output which is notoriously hard to pull off, especially using CMD.

So it's probably easier to just generate an extra -Djbang.version=1.2.3 argument.

quintesse avatar Sep 01 '22 08:09 quintesse

There is a version.txt in the cache folder.

~/.jbang/cache/version.txt

This file has 0.106.1 on my laptop.

But I just upgraded to 0.106.3 via skdman

~/workspace ❯ cat ~/.jbang/cache/version.txt 0.106.1% ~/workspace ❯ jbang -V 0.106.3

davsclaus avatar Apr 17 '23 19:04 davsclaus

Yes, that only gets updated once JBang checks for a new version (which you can force by running jbang version -- check IIRC)

quintesse avatar Apr 17 '23 21:04 quintesse