refactor: update CommandBuilder methods to use addAll for multiple arguments#5275
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the CommandBuilder class to provide clearer API semantics by splitting the varargs add(String... args) method into two distinct methods: add(String) for single arguments and addAll(String...) for multiple arguments. The refactoring also fixes a bug where the system proxy property was incorrectly split into two separate command line arguments.
Changes:
- Added new
add(String arg)method toCommandBuilderfor single argument addition - Renamed existing
add(String... args)toaddAll(String... args)to better express intent for multiple arguments - Updated all call sites across the codebase to use the appropriate method
- Fixed bug where
-Djava.net.useSystemProxies=andtruewere added as separate arguments instead of a single concatenated argument
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java | Added add(String) method and renamed add(String...) to addAll(String...) |
| HMCLCore/src/main/java/org/jackhuang/hmcl/launch/DefaultLauncher.java | Updated method calls to use addAll() for multiple arguments and fixed proxy option bug |
| HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java | Updated method call to use addAll() for multiple arguments |
Comments suppressed due to low confidence (1)
HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/CommandBuilder.java:72
- Consider adding unit tests for the new add and addAll methods to verify their behavior with single and multiple arguments. The repository has comprehensive test coverage for other utility classes in the same package, and testing would help ensure the API refactoring works correctly across different scenarios.
public CommandBuilder add(String arg) {
raw.add(new Item(arg, true));
return this;
}
/**
* Parsing will ignore your manual escaping
*
* @param args commands
* @return this
*/
public CommandBuilder addAll(String... args) {
for (String s : args)
raw.add(new Item(s, true));
return this;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Parsing will ignore your manual escaping | ||
| * | ||
| * @param arg command | ||
| * @return this | ||
| */ | ||
| public CommandBuilder add(String arg) { | ||
| raw.add(new Item(arg, true)); | ||
| return this; | ||
| } |
There was a problem hiding this comment.
The javadoc for the new add method should clarify the difference from addAll. Consider updating the documentation to specify that add accepts a single argument while addAll accepts multiple arguments, to help API consumers choose the correct method.
No description provided.