Skip to content

Option & Flag arguments #25

@Matt-MX

Description

@Matt-MX

Declarative commands should have a flag/option argument type introduced.

Example implementation

val player by username()
val after by optionArgument<Date>()
val order by optionArgument<OrderByEnum>()
val boolean_option by flag()

("history" / player) {
    + after // Register the after argument
    + order // Alternatively call .withKeyValue(order) for java

    runs<CommandSender> {
        val records = Database.queryHistory(player)
            .recordsAfterDate(after())
            .orderBy(order())
            .get()
            
        if (records.isEmpty)
            return@runs reply(!"&cThat user has no records.")
            
        for (record in records) {
            reply(!record)
        }
    }
} register this

This example command would be invoked like this:

/history MattMX --after 13/06/2024 --order date_asc --boolean-option

The argument type's format should be relatively customizable.

/history MattMX -after:13/06/2024 -order:date_asc -boolean-option

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions