You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Initial change after issue #135 (Method parse signature clash when using from Groovy API) was to rename the instance method from parse to parseCommands, and keep the static parse method unchanged.
I'm now thinking to revisit that decision.
One reason is that the static parse method makes it easy for users to make this mistake:
String[] args = //...
CommandLine cmd = new CommandLine(new App());
cmd.parse(args); // wrong: will interpret first arg as the command to initialize
Another reason is that there are many scenarios that don't involve subcommands where the user wants to call the instance method, not the static method: when type converters are registered, or any other kind of configuration (allow overwritten options, etc, - more of these options to come).
So the instance method may actually be the common use case.
One idea is to keep the static method, but rename it to initialize, and validate that the first argument has @Option or @Parameters annotations.
Another idea is to remove the static parse method altogether.
The text was updated successfully, but these errors were encountered:
The static method is now called populateCommand and the instance method is renamed to parse.
I hope this naming is more intuitive, but there is no compiler check to prevent users from mistakenly calling the static method without a command object to initialize:
String[] args = //...
CommandLine cmd = new CommandLine(new App());
cmd.populateCommand(args); // wrong: will interpret first arg as the command to initialize
I'm still unsure if the static method should be removed altogether.
For now, I've added validation to throw an IllegalArgumentException if a CommandLine is constructed with an object not annotated with @command, @option or @parameters.
Initial change after issue #135 (Method parse signature clash when using from Groovy API) was to rename the instance method from
parse
toparseCommands
, and keep the staticparse
method unchanged.I'm now thinking to revisit that decision.
One reason is that the static parse method makes it easy for users to make this mistake:
Another reason is that there are many scenarios that don't involve subcommands where the user wants to call the instance method, not the static method: when type converters are registered, or any other kind of configuration (allow overwritten options, etc, - more of these options to come).
So the instance method may actually be the common use case.
One idea is to keep the static method, but rename it to
initialize
, and validate that the first argument has@Option
or@Parameters
annotations.Another idea is to remove the static
parse
method altogether.The text was updated successfully, but these errors were encountered: