From 9e05ec43397dfdc944cf34a62d0ad54f1479996b Mon Sep 17 00:00:00 2001 From: Andrea Richiardi Date: Thu, 22 Feb 2024 09:58:36 -0700 Subject: [PATCH] Add Aliases section to README.md Here is a bit of docs around the use cases described in #82. --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 653f44b..297f512 100644 --- a/README.md +++ b/README.md @@ -411,6 +411,39 @@ For example to add a header row with labels for each column, you could do someth :indent 2}) ``` +### Aliases + +An `:alias` specifies a mapping from short to long name. + +The library can distinguish aliases with characters in common, so a way to implement the common `-v`/`-vv` unix pattern is: +``` clojure +(def spec {:verbose {:alias :v + :desc "Enable verbose output."} + :very-verbose {:alias :vv + :desc "Enable very verbose output."}}) +``` + +You get: + +```clojure +(cli/parse-opts ["-v"] {:spec spec}) +;;=> {:verbose true} + +(cli/parse-opts ["-vv"] {:spec spec}) +;;=> {:very-verbose true} +``` + +Another way would be to collect the flags in a vector with `:coerce` (and base verbosity on the size of that vector): + +``` clojure +(def spec {:verbose {:alias :v + :desc "Enable verbose output." + :coerce []}}) + +user=> (cli/parse-opts ["-vvv"] {:spec spec}) +{:verbose [true true true]} +``` + ## Subcommands To handle subcommands, use