Command line parser with good subcommand and help handling
To use the latest release, add the following to your deps.edn
(Clojure CLI)
com.lambdaisland/cli {:mvn/version "0.2.11-alpha"}
or add the following to your project.clj
(Leiningen)
[com.lambdaisland/cli "0.2.11-alpha"]
This is an opinionated CLI argument handling library. It is meant for command
line tools with subcommands (for example git, which has git commit
, git log
and so forth). It works exactly how we like it, which mostly means it sticks to
common conventions (in particular the prominent GNU conventions), needs little
ceremony, and provides your tool with built-in help facilities automagically.
It is Babashka compatible, and in fact pairs really nicely with bb
for making
home-grown or general purpose tools.
(require '[lambdaisland.cli :as cli])
(cli/dispatch
{:commands
["run"
{:description "Run the thing"
:command (fn [args flags]
,,,)}
"widgets"
{:description "Work with widgets"
:subcommands
["ls"
{:description "List widgets"
:command (fn [args flags] ,,,)}
"create NAME"
{:description "Create a new widget"
:command (fn [args flags] ,,,)}
"delete ID"
{:description "Delete the widget with the given ID"
:command (fn [args flags] ,,,)}]}]
:flags
["-v,--verbose" {:description "Increase verbosity"}]})
Thank you! cli is made possible thanks to our generous backers. Become a backer on OpenCollective so that we can continue to make cli better.
cli is part of a growing collection of quality Clojure libraries created and maintained by the fine folks at Gaiwan.
Pay it forward by becoming a backer on our OpenCollective, so that we continue to enjoy a thriving Clojure ecosystem.
You can find an overview of all our different projects at lambdaisland/open-source.
We warmly welcome patches to cli. Please keep in mind the following:
*
**
We would very much appreciate it if you also
We recommend opening an issue first, before opening a pull request. That way we can make sure we agree what the problem is, and discuss how best to solve it. This is especially true if you add new dependencies, or significantly increase the API surface. In cases like these we need to decide if these changes are in line with the project's goals.
*
This goes for features too, a feature needs to solve a problem. State the problem it solves first, only then move on to solving it.
**
Projects that have a version that starts with 0.
may still see breaking changes, although we also consider the level of community adoption. The more widespread a project is, the less likely we're willing to introduce breakage. See LambdaIsland-flavored Versioning for more info.
Copyright © 2024 Arne Brasseur and Contributors
Licensed under the term of the Mozilla Public License 2.0, see LICENSE.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close