CLI.App
bundles a program description with a set of named subcommands, each
its own Parser — the shape of a tool like git or docker, where
git commit and git push are independent parsers with their own options and
positionals. Build one with App.new and App.add, then
dispatch with App.parse. Adding subcommands is purely additive: a
plain Parser still works exactly as before.
add
(Fn [CLI.App, (Ref String a), (Ref CLI.Parser a)] CLI.App)
(add app name p)
registers the subcommand name, handled by the parser p, on the
App app.
commands
(Fn [(Ref CLI.App a)] (Ref (Array (Pair String (Box CLI.Parser))) a))
gets the commands property of a App.
description
(Fn [(Ref CLI.App a)] (Ref String a))
gets the description property of a App.
has?
(Fn [(Ref CLI.App a), (Ref String a)] Bool)
(has? app name)
returns whether the App app knows a subcommand called
name.
new
(Fn [String] CLI.App)
(new descr)
creates a new App with program description descr and no
subcommands yet.
parse
(Fn [(Ref CLI.App a)] CLI.Dispatch)
(parse app)
dispatches the process arguments to one of the subcommands of
the App app. See parse-from for the result shape.
parse-from
(Fn [(Ref CLI.App a), (Ref (Array String) a)] CLI.Dispatch)
(parse-from app args)
dispatches the argument array args to one of the
subcommands of the App app, returning a Dispatch.
The first token selects the subcommand and the remaining tokens are parsed by
that subcommand’s Parser. A leading --help/-h (before any
subcommand) yields AppHelp; any other leading option is a Failure —
options come after the subcommand, not before it. A recognized subcommand
yields Parsed on success, CommandHelp (carrying the subcommand name) if that
subcommand’s own --help/-h was requested, or a Failure with its parse
error otherwise. A missing or unknown subcommand is a Failure.
set-commands
(Fn [CLI.App, (Array (Pair String (Box CLI.Parser)))] CLI.App)
sets the commands property of a App.
set-commands!
(Fn [(Ref CLI.App a), (Array (Pair String (Box CLI.Parser)))] ())
sets the commands property of a App in place.
set-description!
(Fn [(Ref CLI.App a), String] ())
sets the description property of a App in place.
update-commands
(Fn [CLI.App, (Ref (Fn [(Array (Pair String (Box CLI.Parser)))] (Array (Pair String (Box CLI.Parser))) a) b)] CLI.App)
updates the commands property of a CLI.App using a function f.
update-description
(Fn [CLI.App, (Ref (Fn [String] String a) b)] CLI.App)
updates the description property of a CLI.App using a function f.
usage
(Fn [(Ref CLI.App a)] ())
(usage app)
prints the available subcommands of the App app with their
descriptions.
usage-for
(Fn [(Ref CLI.App a), (Ref String a)] ())
(usage-for app name)
prints the detailed usage of the single subcommand name of
the App app, or an error if there is no such subcommand.