Skip to content

Commit

Permalink
solve issue #501
Browse files Browse the repository at this point in the history
  • Loading branch information
HennyNile committed May 21, 2021
1 parent 947cd54 commit b7abc5b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/beust/jcommander/JCommander.java
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,13 @@ private String[] expandArgs(String[] originalArgv) {
for (String arg : originalArgv) {

if (arg.startsWith("@") && options.expandAtSign) {
String fileName = arg.substring(1);
vResult1.addAll(readFile(fileName));
if(arg.startsWith("@/")){
List<String> expanded = expandDynamicArg(arg.substring(2,arg.length()));
vResult1.addAll(expanded);
}else {
String fileName = arg.substring(1);
vResult1.addAll(readFile(fileName));
}
} else {
List<String> expanded = expandDynamicArg(arg);
vResult1.addAll(expanded);
Expand Down
30 changes: 30 additions & 0 deletions src/test/java/com/beust/jcommander/JCommanderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1433,4 +1433,34 @@ class Args {
public static void main(String[] args) {
new JCommanderTest().trimTest();
}

@Test(expectedExceptions = java.nio.file.NoSuchFileException.class)
public void syntaxTest_1()
{
class Args{
@Parameter(names = "-password",description = "parameter starts with @")
public String x = "password";
}
Args args = new Args();
JCommander.newBuilder()
.addObject(args)
.build()
.parse("-password","@X");
Assert.assertEquals("@X", args.x);
}

@Test
public void syntaxTest_2()
{
class Args{
@Parameter(names = "-password",description = "parameter starts with @")
public String x = "password";
}
Args args = new Args();
JCommander.newBuilder()
.addObject(args)
.build()
.parse("-password","@/@X");
Assert.assertEquals("@X", args.x);
}
}

0 comments on commit b7abc5b

Please sign in to comment.