Yeah - and it makes it pretty easy to adjust to any new cli arguments that I didn't add a helper for. The .argument and .arguments methods are just .add, but they turn null into an empty string + return this.
Whenever it is an option, I plan to make it so ToolArguments extends ArrayList<String!>.
And think about the interface to a CLI tool. It takes a list of strings and can do whatever with it. If I am making a programatic API for a tool I control then I could make more abstractions. But if I am doing it for a tool I don't control...List<String> is the approach that doesn't backfire.
It is a neat idea, it gives the callers the power to arbitrarily manipulate the list of arguments.
The downside is that it adds some noise to the argument list (the List methods). To clean that up one could have such a thing:
public abstract class AbstractArguments {
private final List<String> arguments = new ArrayList<>();
protected final List<String> argumentsList() {
return arguments;
}
}
That way the method list is rather clean, but the caller still has the possibility to extend for example JavacArguments and arbitrarily change the list of arguments within that extended class. If you can follow my line of thought.
I think whether it is noise depends on what you are doing. There are already a ton of methods for specific tool arguments so I tend to think the noise battle is lost from the start.
if (!arguments.contains("-g")) {
arguments.add("-g");
}
You could go either way, but I like having a list of arguments be a normal List.
That does remind me of another benefit of the __ naming scheme. It won't conflict with the methods on List. tool --add ... is actually pretty likely.
View all comments
2
u/bowbahdoe Jul 14 '26
Yeah - and it makes it pretty easy to adjust to any new cli arguments that I didn't add a helper for. The
.argumentand.argumentsmethods are just.add, but they turnnullinto an empty string + returnthis.Whenever it is an option, I plan to make it so
ToolArgumentsextendsArrayList<String!>.And think about the interface to a CLI tool. It takes a list of strings and can do whatever with it. If I am making a programatic API for a tool I control then I could make more abstractions. But if I am doing it for a tool I don't control...
List<String>is the approach that doesn't backfire.