Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option & Flag arguments #25

Open
Matt-MX opened this issue Jun 13, 2024 · 1 comment
Open

Option & Flag arguments #25

Matt-MX opened this issue Jun 13, 2024 · 1 comment

Comments

@Matt-MX
Copy link
Owner

Matt-MX commented Jun 13, 2024

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
@Matt-MX
Copy link
Owner Author

Matt-MX commented Jun 13, 2024

These arguments should have permissions requirements for whomever executes them.

val max_results by optionArgument<Int>()

// `value` is the supplied value as an Int at invocation.
max_results requires { sender.getHighestPermissionLevel("history.max_results") >= value }
max_results permission { sender.reply(!"&cYou can't query that many max results!") }
max_resutls default 10

// ...

@Matt-MX Matt-MX changed the title Key-Value arguments Option & Flag arguments Jun 13, 2024
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

No branches or pull requests

1 participant