Skip to content

Support subcommand methods in Groovy scripts #1191

@attiand

Description

@attiand

I’m not sure if this is supposed to work, but it would be very cool if it did.

@Grab('info.picocli:picocli-groovy:4.5.1')
@GrabConfig(systemClassLoader = true)
@Command(name = "picocli",
        mixinStandardHelpOptions = true,
        version = '1.0.0',
        subcommands = [ HelpCommand.class ],
        description = 'sub command test')

@picocli.groovy.PicocliScript
import static picocli.CommandLine.*


@Command(description = "Record changes to the repository")
void commit(@Option(names = ["-m", "--message"]) String commitMessage,
            @Option(names = "--squash", paramLabel = "<commit>") String squash,
            @Parameters(paramLabel = "<file>") File[] files) {

    println "commit ${files}"
}

println "done"

The groovy script seems to pick up the sub command in the usage help, but i can’t get the script to call the commit method.

./picocli.groovy --help
Usage: picocli [-hV] [COMMAND]
sub command test
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  help    Displays help information about the specified command
  commit  Record changes to the repository


./picocli.groovy commit picocli.groovy 
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    theme: compatibilityIssues related to binary and source backwards compatibilitytheme: integrationAn issue or change related to integration with other frameworks, shells or operating systemstype: API 🔌type: enhancement ✨

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions