Liking cljdoc? Tell your friends :D

lambdaisland.cli

Command line argument parsing and handling

With support for subcommands, following UNIX conventions.

Command line argument parsing and handling

With support for subcommands, following UNIX conventions.
raw docstring

*opts*clj

source

add-defaultsclj

(add-defaults init-opts flagpairs)
source

append-middlewareclj

(append-middleware opts {mw :middleware})
source

append-middleware*clj

(append-middleware* opts mw)
source

assoc-flagclj

(assoc-flag opts {:keys [middleware handler] :as flagspec} & args)
source

bind-opts-mwclj

(bind-opts-mw)
source

call-handlerclj

(call-handler handler opts & args)
source

default-parseclj

(default-parse s)
source

dispatchclj

(dispatch & args)

Main entry point for com.lambdaisland/cli.

Takes either a single var, or a map describing the commands and flags that your CLI tool accepts. At a minimum it should contain either a :command or :commands, optionally followed by a vector of positional command line arguments (this second argument can generally be omitted, since we can access these through [[command-line-args]]).

  • :name Name of the script/command as used in the shell, used in the help text
  • :command Function that implements your command logic, receives a map of parsed CLI args. Can be a var, in which case additional configuration can be done through var metadata.
  • :commands Map or flat vector of command-string command-map pairs
  • :doc Docstring, taken from :command if it is a var.
  • :flags Map or flat vector of flag-string flag-map
  • :argnames Vector of positional argument names, only needed on the top level, for subcommands use the command-string to specify these.
  • :init map or zero-arity function that provides the base options map, that parsed flags and arguments are added onto

These flags can also be used in (sub)command maps, with the exception of :name, :argnames, and :init.

A command-string consists of the name of the command, optionally followed by any named positional argument, either in all-caps, or delineated by angle brackets, e.g. create <id> <name> or delete ID.

A flag-string consists of command separated short (single-dash) or long (double-dash) flags, optionally followed by an argument name, either in all-caps, or delineated by angle brackets. The flag and argument are separated by either a space or an equals sign. e.g. --input=<filename>, -o, --output FILENAME.

Flag-maps can contain

  • :doc Docstring, used in the help text
  • :parse Function that parses/coerces the flag argument from string.
  • :default Default value, gets passed through :parse if it's a string.
  • :handler Function that transforms the options map when this flag is present. Single-arity for boolean (no-argument) flag, two-arity for flags that take an argument.
  • :middleware Function or sequence of functions that will wrap the command function if this flag is present.
  • :required Boolean value to indicate if the flag is required.

This docstring is just a summary, see the com.lambdaisland/cli README for details.

Main entry point for com.lambdaisland/cli.

Takes either a single var, or a map describing the commands and flags that
your CLI tool accepts. At a minimum it should contain either a `:command` or
`:commands`, optionally followed by a vector of positional command line
arguments (this second argument can generally be omitted, since we can access
these through [[*command-line-args*]]).

- `:name` Name of the script/command as used in the shell, used in the help text
- `:command` Function that implements your command logic, receives a map of
  parsed CLI args. Can be a var, in which case additional configuration can be
  done through var metadata.
- `:commands` Map or flat vector of command-string command-map pairs
- `:doc` Docstring, taken from `:command` if it is a var.
- `:flags` Map or flat vector of flag-string flag-map
- `:argnames` Vector of positional argument names, only needed on the top
  level, for subcommands use the command-string to specify these.
- `:init` map or zero-arity function that provides the base options map, that
  parsed flags and arguments are added onto

These flags can also be used in (sub)command maps, with the exception of
`:name`, `:argnames`, and `:init`.

A command-string consists of the name of the command, optionally followed by
any named positional argument, either in all-caps, or delineated by angle
brackets, e.g. `create <id> <name>` or `delete ID`.

A flag-string consists of command separated short (single-dash) or
long (double-dash) flags, optionally followed by an argument name, either in
all-caps, or delineated by angle brackets. The flag and argument are separated
by either a space or an equals sign. e.g. `--input=<filename>`, `-o, --output
FILENAME`.

Flag-maps can contain
- `:doc` Docstring, used in the help text
- `:parse` Function that parses/coerces the flag argument from string.
- `:default` Default value, gets passed through `:parse` if it's a string.
- `:handler` Function that transforms the options map when this flag is
  present. Single-arity for boolean (no-argument) flag, two-arity for flags that
  take an argument.
- `:middleware` Function or sequence of functions that will wrap the command
  function if this flag is present.
- `:required` Boolean value to indicate if the flag is required.

This docstring is just a summary, see the `com.lambdaisland/cli` README for
details.
 
sourceraw docstring

dispatch*clj

(dispatch* cmdspec)
(dispatch* {:keys [flags init] :as cmdspec} cli-args)
(dispatch* {:keys [commands doc argnames command flags flagpairs flagmap
                   middleware]
            :as cmdspec
            program-name :name
            :or {program-name "cli"}}
           pos-args
           opts)
source

handle-flagclj

(handle-flag {:keys [flagmap strict?] :as cmdspec} flag cli-args args flags)
source

help-mwclj

(help-mw {:keys [name doc argnames flagpairs] :or {name "cli"}})
source

long?clj

(long? f)
source

missing-flagsclj

(missing-flags flagmap opts)

Return a set of required flags in flagmap not present in opts, or nil if all required flags are present.

Return a set of required flags in `flagmap` not present in `opts`, or `nil` if
all required flags are present.
sourceraw docstring

missing-flags-mwclj

(missing-flags-mw {:keys [flagmap]})
source

parse-error!clj

(parse-error! & msg)
source

prepend-middleware*clj

(prepend-middleware* opts mw)
source

(print-help cmd-name doc command-pairs argnames flagpairs)
source

(print-table rows)
(print-table rows {:keys [pad] :or {pad 2}})
source

short?clj

(short? f)
source

spill-linesclj

(spill-lines segments width)
source

split-flagsclj

(split-flags cmdspec cli-args opts)

Main processing loop, go over raw arguments, split into positional and flags, building up an argument vector, and flag/options map.

Main processing loop, go over raw arguments, split into positional and flags,
building up an argument vector, and flag/options map.
sourceraw docstring

transposeclj

(transpose m)
source

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close