jbang icon indicating copy to clipboard operation
jbang copied to clipboard

jbang init gives no error and generates no file when using existing file as part of name

Open maxandersen opened this issue 6 months ago • 1 comments

discovered this using jbang idea that has a bug and create this kind of jbang init:

 jbang --verbose init --template agent someexistingfile.java/wonka.java

This result in printing that someexistingfile.java/wonka.java is created - when it most definitely was not ;)

expect to error saying that it can not create such file

maxandersen avatar May 18 '25 07:05 maxandersen

The error could be fixed by:

  1. First converting the file path to an absolute path using "new File(filepath).getAbsolutePath()".
  2. Check that each dirname in the absolute path is a directory (if it exists) and not a file
$ ls -l

total 0

$ jbang --verbose init --template agent wonka.java

[jbang] [0:625] jbang version 0.126.1
[jbang] [0:650] Reading catalog from /home/wfouche/.jbang/implicit-catalog.json
[jbang] [0:733] Reading catalog from classpath:/jbang-catalog.json
[jbang] [2025-05-18 22:02:34] Logging Provider: org.jboss.logging.JDKLoggerProvider
[jbang] [0:889] File initialized. You can now run it with 'jbang wonka.java' or edit it using 'jbang edit --open=[editor] wonka.java' where [editor] is your editor or IDE, e.g. 'cursor'. If your IDE supports JBang, you can edit the directory instead: 'jbang edit . wonka.java'. See https://jbang.dev/ide
[jbang] [2025-05-18 22:02:34] Runtime.exit() called with status: 0

$ ls -l
total 4
-rwxrw-r-- 1 admin admin 1680 May 18 22:02 wonka.java

$ jbang --verbose init --template agent wonka.java/wonka.java

[jbang] [0:621] jbang version 0.126.1
[jbang] [0:648] Reading catalog from /home/wfouche/.jbang/implicit-catalog.json
[jbang] [0:731] Reading catalog from classpath:/jbang-catalog.json
[jbang] [2025-05-18 22:02:49] Logging Provider: org.jboss.logging.JDKLoggerProvider
[jbang] [0:869] File initialized. You can now run it with 'jbang wonka.java/wonka.java' or edit it using 'jbang edit --open=[editor] wonka.java/wonka.java' where [editor] is your editor or IDE, e.g. 'cursor'. If your IDE supports JBang, you can edit the directory instead: 'jbang edit . wonka.java/wonka.java'. See https://jbang.dev/ide
[jbang] [2025-05-18 22:02:49] Runtime.exit() called with status: 0

$ ls -l

total 4
-rwxrw-r-- 1 admin admin 1680 May 18 22:02 wonka.java

wfouche avatar May 18 '25 20:05 wfouche