Skip to content

Commit

Permalink
Fixed reading from file when using standard separator (" ")
Browse files Browse the repository at this point in the history
splitting and trimming for list parameters
Revert "splitting and trimming for list parameters"

This reverts commit dc60698.

splitting and trimming for list parameters
Revert "splitting and trimming for list parameters"

This reverts commit 2f76521.
  • Loading branch information
TKlerx committed Apr 8, 2015
1 parent cea0c16 commit f225dda
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/main/java/com/beust/jcommander/JCommander.java
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,28 @@ private String[] expandArgs(String[] originalArgv) {
// Expand @
//
for (String arg : originalArgv) {

if (arg.startsWith("@")) {
String fileName = arg.substring(1);
vResult1.addAll(readFile(fileName));
}
List<String> fileArgs = readFile(fileName);
List<String> splitFileArgs = Lists.newArrayList();
//special treatment for standard separator (" ")
String[] v1 = fileArgs.toArray(new String[0]);
for (int i = 0; i < fileArgs.size(); i++) {
String arg2 = fileArgs.get(i);
if (isOption(v1, arg2)) {
String sep = getSeparatorFor(v1, arg2);
if (" ".equals(sep)) {
String[] sp = arg2.split("[" + sep + "]", 2);
for (String ssp : sp) {
splitFileArgs.add(ssp);
}
}else{
splitFileArgs.add(arg2);
}
}
}
vResult1.addAll(splitFileArgs);
}
else {
List<String> expanded = expandDynamicArg(arg);
vResult1.addAll(expanded);
Expand Down Expand Up @@ -481,9 +498,9 @@ private static List<String> readFile(String fileName) {

try {
BufferedReader bufRead = new BufferedReader(new FileReader(fileName));

String line;

// Read through file one line at time. Print line # and line
while ((line = bufRead.readLine()) != null) {
// Allow empty lines and # comments in these at files
Expand Down

0 comments on commit f225dda

Please sign in to comment.