Skip to content

Commit e047d74

Browse files
committed
refactoring
1 parent 2d2fa7d commit e047d74

1 file changed

Lines changed: 12 additions & 43 deletions

File tree

core/src/main/java/net/jbock/util/ParseRequest.java

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
import io.jbock.util.Either;
44

5-
import java.nio.file.Path;
65
import java.nio.file.Paths;
76
import java.util.List;
8-
import java.util.Optional;
97

108
/**
11-
* Input for the generated parser.
9+
* A convenience class that performs {@code @-file} expansion,
10+
* if the first token in the command line input starts with an
11+
* {@code "@"} character.
1212
*/
1313
public abstract class ParseRequest {
1414

1515
/**
1616
* Creates a {@code ParseRequest}.
17-
* {@code @-file} expansion will be enabled if the input array is nonempty,
18-
* and the first token starts with an {@code "@"} character.
17+
* {@code @-file} expansion will be performed if the input array is nonempty,
18+
* and the first token contains at least 2 characters, and starts with an
19+
* {@code "@"} character.
1920
*
2021
* @param args command line input
2122
* @return a parse request
@@ -26,49 +27,17 @@ public static ParseRequest from(String[] args) {
2627
&& args[0].startsWith("@")) {
2728
String fileName = args[0].substring(1);
2829
List<String> rest = List.of(args).subList(1, args.length);
29-
return expand(Paths.get(fileName), rest);
30+
return new ParseRequestExpand(Paths.get(fileName), rest);
3031
}
31-
return simple(List.of(args));
32+
return new ParseRequestSimple(List.of(args));
3233
}
3334

3435
/**
35-
* Creates a {@code ParseRequest} that indicates {@code @-file} expansion should
36-
* not be performed.
36+
* Returns a Right containing the result of {@code @-file} expansion.
37+
* If an error occurs during {@code @-file} reading, returns a Left containing
38+
* a description of the error.
3739
*
38-
* @param args command line input
39-
* @return a parse request
40-
*/
41-
public static ParseRequest simple(List<String> args) {
42-
return new ParseRequestSimple(args);
43-
}
44-
45-
/**
46-
* Creates a {@code ParseRequest} that indicates {@code @-file} expansion should
47-
* be performed.
48-
*
49-
* @param atFile the {@code @-file}
50-
* @param rest additional command line arguments
51-
* @return a parse request
52-
*/
53-
public static ParseRequest expand(Path atFile, List<String> rest) {
54-
return new ParseRequestExpand(atFile, rest);
55-
}
56-
57-
/**
58-
* Returns the path of the {@code @-file}, or an empty
59-
* {@code Optional} if {@code @-file} expansion is
60-
* not requested.
61-
*
62-
* @return path of the {@code @-file}, or {@code empty}
40+
* @return the result of {@code @-file} expansion
6341
*/
64-
public abstract Optional<Path> path();
65-
66-
/**
67-
* Returns the command line arguments, excluding the {@code @-file}.
68-
*
69-
* @return command line arguments
70-
*/
71-
public abstract List<String> args();
72-
7342
public abstract Either<? extends AtFileError, List<String>> expand();
7443
}

0 commit comments

Comments
 (0)