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

Support for Quoted String and Flag #310

Closed
5 of 6 tasks
huanmeng-qwq opened this issue Nov 27, 2023 · 6 comments · Fixed by #386
Closed
5 of 6 tasks

Support for Quoted String and Flag #310

huanmeng-qwq opened this issue Nov 27, 2023 · 6 comments · Fixed by #386
Assignees
Labels
enhancement New feature or request feature

Comments

@huanmeng-qwq
Copy link
Contributor

huanmeng-qwq commented Nov 27, 2023

PR:

Issues:


I am migrating the framework for command content on a large server project to this project, but I found that it lacks support for Quoted and Flag, and I am not sure if the shortcut annotation supports quick registration of commands with spaces. Here is my examples


/prefix set "§cA §bPrefix"
/tag prefix set "§eB §bPrefix" --updateNow

@Command(name = "tag")
class TaqCommand {
    @Execute(name = "prefix")
    @Shortcut("prefix set")
    fun prefix(@Context user: User, @Arg @Quoted prefix: String, @Flag updateNow: Boolean) {
        /*
        /tag prefix set "§eB §bPrefix" --updateNow
        prefix = "§eB §bPrefix"
        updateNow = true
        */
        /*
        /prefix set "§cA §bPrefix"
        prefix = "A §bPrefix"
        updateNow = false
        */
    }
}

At the same time, I also hope that Flag annotations are not limited to Boolean, but directly support parsing registered arguments. The following are relevant examples

@Command(name = "flagTest")
class FlagTest {
    /*
    /flagTest --enable
    message: Enabled: true

    /flagTest
    message: Enabled: false
    */
    @Execute
    fun bool(@Context user: User, @Flag enable: Boolean) {
        user.sendMessage("Enabled: $enable")
    }

    /*
    /flagTest --text LiteCommands3
    message: Text: LiteCommands

    /flagTest --text LiteCommands3 --world generated-lobby-1
    message:
    Text: LiteCommands
    World: generated-lobby-1
    */
    @Execute
    fun str(@Context user: User, @Flag text: String, @Flag world: World?) {
        user.sendMessage("Text: $text")
        if (world != null) user.sendMessage("World: $world")
    }
}
@Rollczi
Copy link
Owner

Rollczi commented Nov 27, 2023

Hi @huanmeng-qwq, thanks for your feedback.
Introducing @Quoted feature would be a highly beneficial solution, and I suppose it will be introduced soon. Currently @Shortcut don't support spaces in the name, but it is also a feature that we need to add.

The @Flag annotation does not support other types such as String or Integer, for this moment we are using @Arg Optional<String> to create optional arguments. #219

@huanmeng-qwq
Copy link
Contributor Author

I have seen the branches related to quoted strings, and I would like to propose a new suggestion based on #314 , which is to support input of '. When players want to input", they can use '"' to surround it, and vice versa
e.g: /quoted "huanmeng-qwq's Pet" or /quoted 'my name "huanmeng-qwq"'

@huanmeng-qwq
Copy link
Contributor Author

huanmeng-qwq commented Nov 28, 2023

I know to add optional parameters to @Arg Optional<String>, but it's different from @Flag. @Flag can specify the value of a certain parameter, while @Arg needs to input in the order of the code

Of course, I also hope to be able to develop complete Flag features as quickly as possible

@Rollczi
Copy link
Owner

Rollczi commented Dec 1, 2023

I have seen the branches related to quoted strings, and I would like to propose a new suggestion based on #314 , which is to support input of '. When players want to input", they can use '"' to surround it, and vice versa e.g: /quoted "huanmeng-qwq's Pet" or /quoted 'my name "huanmeng-qwq"'

Now a solution to this problem is \"

@huanmeng-qwq
Copy link
Contributor Author

Yes, I have also considered using escape, which is a great implementation!

Rollczi added a commit that referenced this issue Dec 2, 2023
* Add quoted argument resolver. Add related tests.

* Fix example command. Add BanCommand to examples.

* Fix some suggestions bugs.

* Relax input restrictions on quoted strings

* Add test

* Add more use-cases in unit tests then patch them.

---------

Co-authored-by: huanmeng_qwq <1871735932@qq.com>
@huanmeng-qwq
Copy link
Contributor Author

huanmeng-qwq commented Dec 2, 2023

  • @Quoted
  • @Flag
  • @Shortcut spaces in the name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants