我在Clojure中写了一些图书馆,这些图书馆将一些搜索结果删除为一个小型项目。我想在CLI中使用这些库,其中将有一些可以运行的脚本,例如:
- 收集,运行刮擦作业,
- 浏览,浏览先前收集的结果,
- 搜索config,search-config,添加或删除搜索参数。
我想将解决方案作为命令行接口实现:
cljscrape [general flags] subcommand [flags] [args]
我知道您可以使用此帖子,但似乎只能解析标志。如果有人可以推荐如何构建项目,或者可以让我最好地模仿非常棒的模板格式的软件包!
PS
我是Clojure的新手,所以如果我说愚蠢的话,我深表歉意。谢谢! :)
I have written some libraries in clojure that scrape some search results as a small side project. I want to use these libraries in a cli where there would be a few different scripts that could run, like:
- collect, run scraping job,
- browse, browse previously collected results,
- search-config, add or remove search parameters.
I would like to implement the solution as a command line interface as follows:
cljscrape [general flags] subcommand [flags] [args]
I know you can use the packages stated in this post, but it seems to only parse flags. If anyone could recommend how to structure the project, or a package that will allow me to best imitate the template format that would be awesome!
P.S
I am quite new to clojure so I apologise if I say anything stupid. Thanks! :)
发布评论
评论(1)
使用 babashka cli :
var
args
包含一些示例参数。通常,您会从*命令line-args*
或传递给-main
函数的参数获得这些。首先解析一般选项:
请注意,
:opts
现在我们有了分析的一般选项,其余参数(仍然是无与伦比的)保存在中:args
中。当我们依次使用
parse-args
再次解析这些:args
时,我们获得了子命令,选项和参数:因此,您可以使用此两步过程来支持一般参数。
要在子命令上派遣,您可以读取文档在这里。您可以在
function
handle-subcommand
一起使用gragments{:opts {:flag true},:args [args ['arg'']} < /代码>。
An example using babashka CLI:
The var
args
contains some example arguments. Normally you would get these from*command-line-args*
or the arguments passed to a-main
function.First parse the general options:
Note that in
:opts
we now have the parsed general options and the rest of the arguments, still unparsed, are saved inside:args
.When we parse those
:args
in turn again withparse-args
, we get the subcommands, options and arguments:So you can use this two-step process to support general arguments.
To dispatch on the subcommands, you can read the documentation here. You can see the dispatch function in action in the neil project.
For this example, it would be something like:
and function
handle-subcommand
would then be called with the arguments{:opts {:flag true}, :args ["arg"]}
.