Skip to content

Commit

Permalink
Add Aliases section to README.md (#84)
Browse files Browse the repository at this point in the history
Here is a bit of docs around the use cases described in #82.
  • Loading branch information
arichiardi authored Feb 22, 2024
1 parent 1e4ead0 commit de2a348
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit de2a348

Please sign in to comment.