Allow Parameters to be Optional<> #99

Open
opened 2020-06-05 02:35:04 +01:00 by Ghost · 0 comments
Ghost commented 2020-06-05 02:35:04 +01:00 (Migrated from codeberg.org)

Feature Request

Description

Currently, Commandler requires all parameters of Commands be populated, this could be with user input, or through default values.
We should allow omitting a parameter with no default value by making it Optional<?>.
This will allow commands to explicitly state that a parameter isn't required, and doesn't need a default value.

Motivation

We originally didn't allow for null as there is little to no reason to have a command with a null parameter,
so considered null to be a case that shouldn't be considered. However, it appears there may be times an
Optional<?> could be useful, namely when the desired default value might take a complex Java Expression
to produce, or isn't portable between all integrations the command may be intended for.

Interface

public String welcome(@Param("${java expression}") String username) {
    return "Welcome, " + username + "!";
}
public String welcome(@Param Optional<String> username) {
    return "Welcome, " + username.orElse(getOtherUsername()) + "!";
}
# Feature Request <!-- If you feel a heading is irrelevant, just leave it empty or remove it. --> ## Description <!-- Explain what this is about, try to use full sentences, and make your point clear. --> Currently, Commandler requires all parameters of Commands be populated, this could be with user input, or through default values. We should allow omitting a parameter with no default value by making it `Optional<?>`. This will allow commands to explicitly state that a parameter isn't required, and doesn't need a default value. ## Motivation We originally didn't allow for null as there is little to no reason to have a command with a `null` parameter, so considered null to be a case that shouldn't be considered. However, it appears there may be times an `Optional<?>` could be useful, namely when the desired default value might take a complex Java Expression to produce, or isn't portable between all integrations the command may be intended for. ## Interface <!-- In some cases you may wish to propose an interface or method names to help describe how you'd want to use this, or for others to discuss and improve ahead of time before final implementation. --> ```java public String welcome(@Param("${java expression}") String username) { return "Welcome, " + username + "!"; } ``` ```java public String welcome(@Param Optional<String> username) { return "Welcome, " + username.orElse(getOtherUsername()) + "!"; } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
SethFalco/commandler#99
No description provided.