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

App name shows as <script> when cli jruby app is packaged into jar file using warbler #742

Open
hmistry opened this issue Dec 22, 2020 · 0 comments

Comments

@hmistry
Copy link
Contributor

hmistry commented Dec 22, 2020

Problem

I have a CLI app using Thor with jruby and created a compiled jar file using warbler. When viewing the CLI help, the app name shows as <script> instead of my_app_name when running the jar file using java -jar my_app_name.jar help. If I run my_app_name ruby executable directly under jruby using bin/my_app_name, then the app name shows correctly in the help text. See below.

Root Cause

The root cause is because $PROGRAM_NAME is set to <script> when running the jar file so the following method doesn't return the correct app file name as expected. https://github.com/erikhuda/thor/blob/master/lib/thor/base.rb#L674
$PROGRAM_NAME is correctly set when running directly in jruby.

Tried setting package_name but that doesn't work because it only changes Commands: to my_app_name commands:.

Possible fix

One option is to use __FILE__ instead of $PROGRAM_NAME.

Example Test Case

# bin/my_app
class MyApp < Thor
  desc "hammer", "Thor's hammer"
  def hammer()
    "Thor's hammer"
  end
end
# run in project folder -> works as expected
$ bin/my_app help
    Commands:
       my_app hammer
       my_app help [COMMAND]

# package into jar file
$ warble compiled jar
  -> creates my_app.jar

# run jar file -> doesn't work as expected
$ java -jar my_app.jar help
    Commands:
       <script> hammer
       <script> help [COMMAND]

Ruby: jruby v9.2.13
Thor: 1.0.1
Warbler: 2.0.5

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

1 participant