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

Cannot use @-syntax in conjunction with arguments starting with literal @ #501

Closed
c-kunz opened this issue Sep 29, 2020 · 5 comments · Fixed by #520
Closed

Cannot use @-syntax in conjunction with arguments starting with literal @ #501

c-kunz opened this issue Sep 29, 2020 · 5 comments · Fixed by #520
Assignees
Labels
bug Bug

Comments

@c-kunz
Copy link

c-kunz commented Sep 29, 2020

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.

@c-kunz
Copy link
Author

c-kunz commented Sep 29, 2020

Issue #462 might be related:

So... there isn't any externally defined concept of the @file?

@mkarg
Copy link
Collaborator

mkarg commented Sep 29, 2020

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.

@mkarg
Copy link
Collaborator

mkarg commented Sep 29, 2020

See also #330.

@HennyNile
Copy link
Contributor

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.

HennyNile pushed a commit to HennyNile/jcommander that referenced this issue May 21, 2021
HennyNile pushed a commit to HennyNile/jcommander that referenced this issue May 21, 2021
HennyNile pushed a commit to HennyNile/jcommander that referenced this issue May 21, 2021
HennyNile pushed a commit to HennyNile/jcommander that referenced this issue May 21, 2021
@mkarg mkarg added the bug Bug label Aug 11, 2024
@mkarg
Copy link
Collaborator

mkarg commented Aug 11, 2024

@c-kunz Thank you for reporting this bug! It was fixed some minutes ago, and will be contained in either 1.83.1 or 1.84 (whatever comes first).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants