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

defn

(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

instantiate

(Fn [(Ref CLI.App a)] (Ref (Array (Pair String (Box CLI.Parser))) a))

gets the commands property of a App.

copy

instantiate

(Fn [(Ref CLI.App a)] CLI.App)

copies a App.

delete

instantiate

(Fn [CLI.App] ())

deletes a App. Should usually not be called manually.

description

instantiate

(Fn [(Ref CLI.App a)] (Ref String a))

gets the description property of a App.

has?

defn

(Fn [(Ref CLI.App a), (Ref String a)] Bool)

                        (has? app name)
                    

returns whether the App app knows a subcommand called name.

init

instantiate

(Fn [String, (Array (Pair String (Box CLI.Parser)))] CLI.App)

creates a App.

new

defn

(Fn [String] CLI.App)

                        (new descr)
                    

creates a new App with program description descr and no subcommands yet.

parse

defn

(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

defn

(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.

prn

instantiate

(Fn [(Ref CLI.App a)] String)

converts a App to a string.

set-commands

instantiate

(Fn [CLI.App, (Array (Pair String (Box CLI.Parser)))] CLI.App)

sets the commands property of a App.

set-commands!

instantiate

(Fn [(Ref CLI.App a), (Array (Pair String (Box CLI.Parser)))] ())

sets the commands property of a App in place.

set-description

instantiate

(Fn [CLI.App, String] CLI.App)

sets the description property of a App.

set-description!

instantiate

(Fn [(Ref CLI.App a), String] ())

sets the description property of a App in place.

str

instantiate

(Fn [(Ref CLI.App a)] String)

converts a App to a string.

update-commands

instantiate

(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

instantiate

(Fn [CLI.App, (Ref (Fn [String] String a) b)] CLI.App)

updates the description property of a CLI.App using a function f.

usage

defn

(Fn [(Ref CLI.App a)] ())

                        (usage app)
                    

prints the available subcommands of the App app with their descriptions.

usage-for

defn

(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.