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

using picocli to parse commands sent to the bot ? #33

Open
pmauduit opened this issue Mar 30, 2022 · 2 comments
Open

using picocli to parse commands sent to the bot ? #33

pmauduit opened this issue Mar 30, 2022 · 2 comments

Comments

@pmauduit
Copy link
Owner

I'm not very comfortable with parsing the commands sent to the bot with regexps, maybe using a lib like picocli could be a better option for this:
https://picocli.info/#_example_application

@pmauduit
Copy link
Owner Author

@Grab('info.picocli:picocli-groovy:4.6.3')
import picocli.CommandLine
import static picocli.CommandLine.*

class JiraIssueCmd {

    @Parameters(paramLabel = "command")
    def command

    @Parameters(paramLabel = "issue")
    def issueId
}

def jira = new JiraIssueCmd()
def parsed = new CommandLine(jira).parseArgs("!jira GEO-1234".split(" "))

println jira.issueId
println jira.command

returns:

GEO-1234
!jira

This looks promising.

@pmauduit
Copy link
Owner Author

Actually, it won't spend me doing a little bit of parsing:

  1. I have to determine which kind of listener is concerned ("!jira", "!odoo", ...)
  2. I need to figure out the subcommand ("issue", "worklog", ...) to give the expected class representing the command being sent by the user:
[...]
def jira = new JiraIssueCmd()
def msg = "!jira issue GEO-1234".split(" ")

if (msg[0] == "!jira") {
    def parsed = new CommandLine(jira).parseArgs(msg[1..-1] as String[])
}
// then if (msg[1] == "... whatever subcommand") ?

println msg[1..-1]

println jira.issueId
println jira.command

Then maybe having to fiddle with try/catches to properly handle errors.

although picocli is interesting, the formalism is IMHO too strict: I want to chat with my bot, if I would have wanted a "over slack shell interface", it would have sounded relevant.

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