如何在没有选择的情况下在Groovy中使用Clibuilder?
我正在编写一个简单的groovy脚本,我希望命令行很简单,此外
./someTask.groovy task-profile
,该脚本应该具有- help
或-h
选项,该选项指定所有指定所有不同的值可以接受任务范围
。
task-profile
可以采用以下值 -
task-1
task-2
task-3
和- help
选项应告诉用户所有可用的任务范围
值以及如何使用它们。
很多
我搜索了 没有选项的脚本,但只有位置参数,我可以使用交换语句进行编码,但是我想学习使用clibuilder
。任何帮助将不胜感激。
I am writing a simple groovy script for which I want a command line as simple as-
./someTask.groovy task-profile
Also, the script should have a --help
or -h
option which specifies all the different values task-profile
can take.
task-profile
can take the following values-
task-1
task-2
task-3
And the --help
option should tell the users about all available task-profile
values and also how to use them.
I searched a lot but only found examples that had options (eg -a
, -b
, -c
, etc.)
How to write a script that has no option, but only positional parameters, I can hardcode it using switch statements, but I want to learn to use CliBuilder
. Any help will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Clibuilder在Groovy 2.5中更新了 picocli -backed-backed实现(
groovy.cli.cli.picocli。 Clibuilder
)。 本文显示了许多新功能的详细信息,这些详细信息可在Clibuilder中可用。但是,即使在此版本的Clibuilder中,公共API也仅支持位置参数列表,并为该列表提供单个描述。
不幸的是,Clibuilder API当前没有提供一种在您的应用程序的使用帮助消息中显示单独的位置参数(通过单个描述)的方法。
如果您的目标是具有单独的位置参数,则可能具有单独的类型,单独的默认值等,并让使用帮助消息显示每个位置参数的分开描述,那么您可能需要考虑直接使用Picocli(无粘液器)您的时髦脚本或在您的Groovy应用程序中。
Picocli用户手册具有许多令人讨厌的示例,并在使用picocli在Groovy应用程序中使用picocli,在Groovy应用程序和杂乱无章的剧本中。本文(“ nofollow noreferrer”> groovy脚本)也可能有用。 。
这是一个示例
任务构装
带有三个位置参数的脚本脚本:CliBuilder was updated in Groovy 2.5 by adding support for a picocli-backed implementation (
groovy.cli.picocli.CliBuilder
). This article shows many details of the new features that are now available in CliBuilder.However, even in this version of CliBuilder, the public API only supports a list of positional parameters, with a single description for that list.
Unfortunately, the CliBuilder API currently does not provide a way to show separate positional parameters, with individual descriptions, in the usage help message of your application.
If your goal is to have separate positional parameters, perhaps with separate types, separate default values, etc., and let the usage help message show separate descriptions for each positional parameter, then you may want to consider using picocli directly (without CliBuilder) in your Groovy script or in your Groovy application.
The picocli user manual has many Groovy examples and has a dedicated section on using picocli in Groovy applications and Groovy scripts. This article (Groovy Scripts on Steroids) may also be useful.
Here is an example
task-profile
Groovy script with three positional parameters: