<commit_before>Directive
=========

A simple DSL for building command-line interfaces with trees of subcommands.
This library wraps the `org.clojure/tools.cli` library for option parsing.

## Usage

```clojure
(require '[mvxcvi.directive :refer [command execute]])

; ...
```

## License

This is free and unencumbered software released into the public domain.
See the UNLICENSE file for more information.<commit_msg>Update usage info in README.<commit_after>Directive
=========

A simple DSL for building command-line interfaces with trees of subcommands.
This library wraps the `org.clojure/tools.cli` library for option parsing.

## Usage

The `command` macro lets you declare a tree of subcommands, each of which can
have its own options, arguments, and initialization function. Leaf commands
specify an _action_ to take when invoked.

```clojure
(require '[mvxcvi.directive :refer [command execute]])

(def commands
  (command "my-tool [global opts] <command> [command args]"
    "Command-line tool for my awesome project."

    ["--config" "Set path to tool configuration."
     :default config/default-path]
    ["-v" "--verbose" "Show extra debugging messages."
     :flag true :default false]
    ["-h" "--help" "Show usage information."
     :flag true :default false]

    (init config/initialize)

    (command "config <type>"
      "Show configuration information."

      (command "dump"
        "Prints out a raw version of the configuration map."

        ["--pretty" "Formats the info over multiple lines for easier viewing."
         :flag true :default false]

        (action [opts args]
          (if (:pretty opts)
            (pprint opts args)
            (prn opts args)))))

    (command "foo <action> [args]"
      "Low-level commands dealing with foos."

      (init [opts]
        (assoc opts :foo true))

      (action do-foo-action))))

(defn -main [& args]
  (execute commands args))
```

Initialization functions are given the current option map and must return an
updated version of the map in addition to causing any necessary side-effects.
Actions take the option map and a vector of the remaining arguments. Either may
be specified as a symbol or as an inline function body.

## License

This is free and unencumbered software released into the public domain.
See the UNLICENSE file for more information.
{'fraction_non_alphanumeric': 0.09782144382742418, 'fraction_numerical': 0.0, 'mean_word_length': 3.4272211720226844, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '549575', 'n_tokens_mistral': 647, 'n_tokens_neox': 615, 'n_words': 287}