Open pmauduit opened 2 years ago
@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.
Actually, it won't spend me doing a little bit of parsing:
[...]
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.
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