Cannot use @-syntax in conjunction with arguments starting with literal @
c-kunz opened this issue · 5 comments
Description
One cannot use the @
-syntax in conjunction with parameters that may contain a literal @
at the beginning.
Steps to reproduce:
In this repository: https://github.com/c-kunz/jcommander-conflicting-at-syntax
git clone https://github.com/c-kunz/jcommander-conflicting-at-syntax
cd jcommander-conflicting-at-syntax
mvn clean package
java -jar target/demo-jar-with-dependencies.jar -password @X
Expected result
JCommander is able to parse the argument beginning with the literal @
while also being able to parse additional arguments using the @
-syntax.
Actual result
JCommander interprets the argument starting with a literal @
as a file containing additional arguments (@
-syntax):
Exception in thread "main" com.beust.jcommander.ParameterException: Could not read file X: java.nio.file.NoSuchFileException: X
Workaround
One has to settle for the following workaround, basically disabling the @
-syntax altogether:
JCommander cli = ...
cli.setExpandAtSign(false);
Proposal
Since this is an either-or situation, either disabling @
-syntax or prohibiting arguments starting with a literal @
, it would be nice to be able to for example specify parameters that lookup additional arguments in a file or specify parameters that ignore leading @
signs.
Issue #462 might be related:
So... there isn't any externally defined concept of the
@file
?
Proposed Solution
JCommander should have a new option which allows using @
as part of parameter values but still recognizes it as file name prefix when used in parameter names. Hence, the old behavior would be the default, but new applications could opt-in to the new behavior.
Hello, I want to try to work on this issue.
I plan to modify the judge rule of @-syntax which is inspired by that file name can not start with / in windows and linux.