You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
JBang templates are providing ways to reuse the file input name coming as an input from the user. It can be {filename} and {basename}.
If the input is Example.java (jbang init Example.java) the {filename} variable will be Example.java and the {basename} will be Example. That is cool, BUT, look at the following use case:
If I would like to go with this approach (jbang init -t=q-aws-lambda-tf Example.java) the last entry with "lambda-aws-{basename}.tf": "aws/lambda-aws.tf.qute" will cause an error for the Init command because its extension is not .java, it is .tf and the Init commands checks if the {basename} variable is found in a file entry key, then it validates that the entry's key extension matches the input file extension.
Here is the code for the check:
staticPathresolveBaseName(StringrefTarget, StringrefSource, StringoutName) {
Stringresult = refTarget;
if (dev.jbang.cli.Template.TPL_FILENAME_PATTERN.matcher(refTarget).find()
|| dev.jbang.cli.Template.TPL_BASENAME_PATTERN.matcher(refTarget).find()) {
StringbaseName = Util.base(outName);
StringoutExt = Util.extension(outName);
StringtargetExt = Util.extension(refTarget);
if (targetExt.isEmpty()) {
targetExt = refSource.endsWith(".qute") ? Util.extension(Util.base(refSource))
: Util.extension(refSource);
}
if (!outExt.isEmpty() && !outExt.equals(targetExt)) {
thrownewExitException(BaseCommand.EXIT_INVALID_INPUT,
"Template expects " + targetExt + " extension, not " + outExt);
}
result = dev.jbang.cli.Template.TPL_FILENAME_PATTERN.matcher(result).replaceAll(outName);
result = dev.jbang.cli.Template.TPL_BASENAME_PATTERN.matcher(result).replaceAll(baseName);
}
returnPaths.get(result);
}
In my opinion the two variables (filename and basename) should be two different uses cases, I would like to use the {basename} variable in other entries as well, the filename variable is totally understandable, but the basename should be allowed to use with different extensions.
To Reproduce
Above.
Expected behavior
Let the {basename} variable be used for other file entries as well.
JBang version
0.91
The text was updated successfully, but these errors were encountered:
Describe the bug
JBang templates are providing ways to reuse the file input name coming as an input from the user. It can be {filename} and {basename}.
If the input is Example.java (
jbang init Example.java
) the {filename} variable will be Example.java and the {basename} will be Example. That is cool, BUT, look at the following use case:If I would like to go with this approach (
jbang init -t=q-aws-lambda-tf Example.java
) the last entry with"lambda-aws-{basename}.tf": "aws/lambda-aws.tf.qute"
will cause an error for the Init command because its extension is not.java
, it is.tf
and the Init commands checks if the {basename} variable is found in a file entry key, then it validates that the entry's key extension matches the input file extension.Here is the code for the check:
In my opinion the two variables (filename and basename) should be two different uses cases, I would like to use the {basename} variable in other entries as well, the filename variable is totally understandable, but the basename should be allowed to use with different extensions.
To Reproduce
Above.
Expected behavior
Let the {basename} variable be used for other file entries as well.
JBang version
0.91
The text was updated successfully, but these errors were encountered: