l3nz / cli-matic

Compact, hands-free [sub]command line parsing library for Clojure.
Eclipse Public License 2.0
361 stars 29 forks source link

Feature Request: Ability to override generation help text #45

Closed ty-i3 closed 5 years ago

ty-i3 commented 5 years ago

This feature request adds optional functions that override the way cli-matic prints help, affording complete byte-by-byte control over the help text.

Rationale: Our internal CLI tooling needs to adhere to certain policies regarding help and usability for developers. Certain info such as Git build, version string, and grouping of commands needs to be printed in the prescribed format. This feature request would realize the ability to completely control the presentation of generated help text to satisfy those policies.

An example of generating global help:

(def banner
  (str "Welcome to CLI-ABC123, Git "
       build-info/git-hash))

(defn commands-segment
  [cfg]
  (str "Commands:\n"
       (clojure.string/join
         "\n"
         (map
           #(format "   %-10s %s"
                    (get % :command)
                    (get % :description))
           (cfg :commands)))))

(defn my-global-help
  [cfg]
  (clojure.string/join "\n" [banner (commands-segment cfg) ...]))

and using it as the global help text generator:

(run-cmd args {:app {:global-help my-global-help
                     ...}})
l3nz commented 5 years ago

So let me recap; this change adds optional functions that override the way text is output when printing help?

ty-i3 commented 5 years ago

Yes, that's right!

l3nz commented 5 years ago

You'd do me a favor if you were to add an example under examples that shows custom help generation. But I merged your changes and released as 0.1.18

ty-i3 commented 5 years ago

Done as requested.

l3nz commented 5 years ago

Thanks - great!