cli
Jump to function (38) ›
- cli/application
- cli/arg
- cli/argv
- cli/argv-with-stdin
- cli/ask
- cli/ask-hidden
- cli/buffered-output
- cli/caution
- cli/choice
- cli/command
- cli/comment-line
- cli/confirm
- cli/debug
- cli/error
- cli/info
- cli/info-v
- cli/info-vv
- cli/listing
- cli/note
- cli/null-output
- cli/opt
- cli/output->string
- cli/output-contains?
- cli/progress-advance
- cli/progress-bar
- cli/progress-finish
- cli/progress-start
- cli/run
- cli/run-with-progress
- cli/section
- cli/stdin-lines
- cli/style
- cli/success
- cli/table
- cli/title
- cli/warning
- cli/write
- cli/writeln
cli/application#
(application name-or-spec & [commands])
Build a Symfony Application.
Single-arity (preferred): (application {:name "mytool" :version "1.0.0" :commands [...] :default "greet" :auto-exit? false :before on-before-fn ; receives ConsoleCommandEvent :after on-after-fn ; receives ConsoleTerminateEvent :on-error on-error-fn ; receives ConsoleErrorEvent :on-signal {:sigint cleanup-fn :sigterm cleanup-fn}})
Two-arity convenience: (application "mytool" [command-specs...])
Example:
(application {:name "mytool" :commands [spec]})
cli/arg#
(arg ctx name)
Read (and coerce) an argument value by name.
Example:
(arg ctx "port") ; coerced when spec has :coerce :int
cli/argv#
(argv args)
Build an ArgvInput from a vector of string tokens. Positional args
and --flag=value are parsed just like a real shell command line.
Example:
(argv ["greet" "--loud" "alice"])
cli/argv-with-stdin#
(argv-with-stdin args stdin-string)
Like argv but also wires a STDIN stream so ask/confirm/choice
prompts can be tested with canned answers.
Example:
(argv-with-stdin ["greet"] "alice\n")
cli/ask#
(ask ctx question & [default])
Free-text prompt. default optional.
Example:
(ask ctx "Your name?" "alice")
cli/ask-hidden#
(ask-hidden ctx question)
Prompt without echoing (passwords).
cli/buffered-output#
(buffered-output)
Build a BufferedOutput that captures writes into a string.
cli/caution#
(caution ctx text)
Boxed caution message.
cli/choice#
(choice ctx question choices & [default])
Single-choice prompt over a vector of options.
Example:
(choice ctx "Env?" ["dev" "stg" "prod"] "dev")
cli/command#
(command spec)
Build a Symfony Command from a Phel spec map.
Spec keys:
:name command name, e.g. "build" or "app:build" (REQUIRED)
:doc short description (shown in list)
:help long help text (shown in <cmd> --help)
:aliases vector of alternate names
:hidden? true = hide from list
:args vector of arg specs {:name :mode :doc :default :coerce :complete}
:opts vector of option specs {:name :short :mode :doc :default :coerce :complete}
:run handler (fn [ctx] ...), ctx = {:input :output …};
returns nil/0 for success, int for exit code.
Uncaught Throwable rendered as <error>, mapped to exit 1.
Modes :required :optional :array (:args) + :none :negatable (:opts)
Coerce :int :float :bool :keyword :edn
Complete fn (CompletionInput -> vector<string>) for shell completion.
Example:
(command {:name "greet" :run (fn [ctx] (success ctx "Hi!"))})
cli/comment-line#
(comment-line ctx text)
Yellow comment line.
cli/confirm#
(confirm ctx question & [default?])
Yes/no prompt. default? defaults to true.
Example:
(when (confirm ctx "Deploy?") ...)
cli/debug#
(debug ctx text)
Write only when -vvv (debug).
cli/error#
(error ctx text)
Red error line.
cli/info#
(info ctx text)
Green info line.
cli/info-v#
(info-v ctx text)
Write only when -v or higher.
cli/info-vv#
(info-vv ctx text)
Write only when -vv or higher.
cli/listing#
(listing ctx items)
Bulleted list of items.
cli/note#
(note ctx text)
Boxed note.
cli/null-output#
(null-output)
Build a NullOutput that discards writes.
cli/opt#
(opt ctx name)
Read (and coerce) an option value by name.
Example:
(opt ctx "verbose") ; true when --verbose present and :mode :none
cli/output->string#
(output->string output)
Drain a BufferedOutput into a string.
cli/output-contains?#
(output-contains? output-or-result substr)
Test helper. Accepts a BufferedOutput, a string, or a map {:out s}.
Example:
(is (output-contains? res "hello"))
cli/progress-advance#
(progress-advance bar & [n])
Advance by n.
cli/progress-bar#
(progress-bar ctx & [opts])
Create a ProgressBar bound to the context output.
Options:
:max total steps (0 = indeterminate)
:format preset (:normal :verbose :very-verbose :debug :minimal) or custom string
cli/progress-finish#
(progress-finish bar)
Finish + newline.
cli/progress-start#
(progress-start bar)
Start the bar.
cli/run#
(run app & [input output])
Run an Application and return its exit code.
(run app) reads $argv from process;
(run app input) uses supplied InputInterface;
(run app input output) also pipes output (for tests).
Example:
(run (application "t" [spec]))
cli/run-with-progress#
(run-with-progress ctx coll step-fn & [opts])
Iterate coll and invoke (step-fn item bar) for each, handling
start / advance / finish automatically.
Example:
(run-with-progress ctx files (fn [f _] (process f)))
cli/section#
(section ctx text)
Sub-heading.
cli/stdin-lines#
(stdin-lines)
Return a vector of lines from STDIN (trailing \r\n stripped).
Useful for cat data.txt | mytool.
Example:
(for [l :in (stdin-lines) :when (not= l "")] l)
cli/style#
(style ctx)
Return a cached SymfonyStyle bound to the context so successive
ask/confirm/progress calls share state.
Example:
(-> (style ctx) (php/-> (success "Done!")))
cli/success#
(success ctx text)
Boxed success message.
cli/table#
(table ctx headers rows & [opts])
Render an ASCII table.
Options:
:style one of :default :borderless :compact :symfony :box :box-double :markdown
:widths vector of column widths
Example:
(table ctx ["id" "name"] [[1 "alice"] [2 "bob"]])
cli/title#
(title ctx text)
Heavy heading.
cli/warning#
(warning ctx text)
Boxed warning message.
cli/write#
(write ctx text)
Write text without trailing newline.
cli/writeln#
(writeln ctx text)
Write a line.
Example:
(writeln ctx "ready")