Skip to content

refactor: update CommandBuilder methods to use addAll for multiple arguments#5275

Merged
Glavo merged 1 commit into
HMCL-dev:mainfrom
Glavo:command-builder
Jan 21, 2026
Merged

refactor: update CommandBuilder methods to use addAll for multiple arguments#5275
Glavo merged 1 commit into
HMCL-dev:mainfrom
Glavo:command-builder

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Jan 21, 2026

No description provided.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to CommandBuilder for single argument addition
  • Renamed existing add(String... args) to addAll(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= and true were 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.

Comment on lines +51 to +60
/**
* Parsing will ignore your manual escaping
*
* @param arg command
* @return this
*/
public CommandBuilder add(String arg) {
raw.add(new Item(arg, true));
return this;
}
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit ba5e633 into HMCL-dev:main Jan 21, 2026
8 checks passed
@Glavo Glavo deleted the command-builder branch January 21, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants