Liking cljdoc? Tell your friends :D

lambdaisland.cli


*opts*clj

source

add-defaultsclj

(add-defaults init flagpairs)
source

add-middlewareclj

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

add-middleware*clj

(add-middleware* opts mw)
source

add-processed-flagsclj

(add-processed-flags cmdspec extra-flags)

We process flag information for easier use, this results in :flagpairs (ordered sequence of pairs, mainly used in printing help information), and :flagmap (for easy lookup), added to the cmdspec. As we process arguments we may need to add additional flags, based on the current subcommand. This function is used both for the top-level as for subcommand handling of flags.

We process flag information for easier use, this results in
`:flagpairs` (ordered sequence of pairs, mainly used in printing help
information), and `:flagmap` (for easy lookup), added to the `cmdspec`. As we
process arguments we may need to add additional flags, based on the current
subcommand. This function is used both for the top-level as for subcommand
handling of flags.
sourceraw docstring

args-reclj

source

assoc-flagclj

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

bind-opts-mwclj

(bind-opts-mw)
source

build-flagmap-entriesclj

(build-flagmap-entries [flagstr flagopts])
source

call-handlerclj

(call-handler handler opts & args)
source

cmd->flagsclj

(cmd->flags cmdspec args)
source

coerce-to-pairsclj

(coerce-to-pairs o)
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]
            :as cmdspec
            program-name :name
            :or {program-name "cli"}}
           pos-args
           opts)
source

flag-reclj

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-arg-namesclj

(parse-arg-names str)
source

parse-error!clj

(parse-error! & msg)
source

parse-flagstrclj

(parse-flagstr flagstr flagopts)
source

parse-flagstrsclj

(parse-flagstrs flagpairs)
source

prepare-cmdpairsclj

(prepare-cmdpairs commands)
source

prepare-flagpairsclj

(prepare-flagpairs flagstrs)
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

split-flagsclj

(split-flags cmdspec cli-args init)

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

to-cmdspecclj

(to-cmdspec ?var)
source

transposeclj

(transpose m)
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close