Introduction
lcli (pronounced "Elk-ly") is a semi-opinionated library for creating command line tools and supporting options (flags) and arguments (non-flag parameters) parsing. Regular options parsing is done using the Erlang getopt community library. lcli manages the handling of commands and nested subcommands.
This library attempts to provide CLI-tool-building capabilities to LFE developers in such a way that it feels LFE-idiomatic. Two excellet libraries have served as inspiration, from two different programming languages: Rust's clap and Go's kong (with the former having a bigger influence).
Erlang getopt
Wrapper and More
lcli provides a very thing wrapper around getopt, basically converting to and from the getopt spec tuple with LFE/Erlang maps.
In addition, lcli provides command and subcommand support where the command spec is a superset of the getopt spec (thus allowing us to use the getopt library transparently).
With lcli
, you have the option of defining specs as maps or as getopt
specs; each has its own aestheic tradeoffs. Note that with maps, the name is optional (taken from the long option name if missing).
Example map specs:
'(#m(long "host" short #\h type string default "localhost"
help "Database server host")
#m(long "port" short #\p type integer
help "Database server port")
#m(long "dbname" type string default "users"
help "Database name")
#m(name xml short #\x help "Output data in XML")
#m(long "verbose" short #\v type integer help "Verbosity level")
#m(name file type string help "Output file"))
Example getopt
specs:
'(#(host #\h "host" #(string "localhost") "Database server host")
#(port #\p "port" integer "Database server port")
#(dbname undefined "dbname"#(string "users") "Database name")
#(xml #\x "xml" undefined undefined "Output data in XML")
#(verbose #\v "verbose" integer "Verbosity level")
#(file undefined undefined string "Output file"))
Differences from lfescript
↟
This library does not use lfescript
as its basis, but rather the lfe
executable itself. As such, a main
function is not run automatically. Instead, the final line of the script must call the entrypoint function.
Examples
Example scripts (some not using lcli, for demonstration purposes) are available here:
If you've created a simple script that shows off some nice functionality of "Elkly", you are encouraged to submit a PR for inclusion here!
CLI "Apps"
TBD
Commands
TBD
Subcommands
More sophisticated usage can create subcommands, etc., for creating command line tools with potentially vast arrays of functionality:
TBD