···1616 users don't have the cmdliner library installed (#243).
1717 Thanks to Brian Ward for suggesting.
18181919+- Add alternative instructions to the cookbook for installing tool support
2020+ files with `dune` (#250).
2121+ Thanks to Brian Ward for the patch and research.
2222+1923- Help output, improve graceful degration on groff or pager errors (#140).
2024 Thanks to Sergey Fedorov for the report.
2125
+56-8
doc/cookbook.mld
···9696you have conventions that clash with [Cmdliner]'s ones but you need to
9797preserve backward compatibility, one way of proceeding is to
9898pre-process {!Sys.argv} into a new array of the right shape before
9999-giving it to command {{!Cmdliner.Cmd.section-eval}evaluation
100100-functions} via the [?argv] optional argument.
9999+giving it to command {{!Cmdliner.Cmd.section-eval}evaluation functions}
100100+via the [?argv] optional argument.
101101102102These are two common cases:
103103···213213opam filter [{cmdliner:installed}] after the closing bracket of the command
214214invocation.
215215216216+{3:top_tool_support_with_dune_install With [dune] [@install]}
217217+218218+Users of [dune] 3.5 or later can use the [cmdliner install
219219+tool-support] command described above, along with the
220220+{{:https://dune.readthedocs.io/en/stable/reference/dune/rule.html#directory-targets}
221221+[directory-targets]}
222222+feature and
223223+{{:https://dune.readthedocs.io/en/latest/reference/dune/install.html}
224224+[install]} stanza, to hook into the existing [dune build @install] command.
225225+226226+For an executable named [mytool] defined in a [dune] file, you can add
227227+the following to the same [dune] file to populate the completion
228228+scripts and manpages when running [dune build @install] (which is what
229229+is used by [opam install]):
230230+231231+{@dune[
232232+(rule
233233+ (target (dir cmdliner-support))
234234+ (deps mytool.exe)
235235+ (action
236236+ (ignore-stdout
237237+ (run cmdliner install tool-support ./mytool.exe:mytool cmdliner-support))))
238238+239239+(install
240240+ (section share_root)
241241+ (dirs (cmdliner-support/share as .)))
242242+]}
243243+244244+If these features of dune are not available to your project, you may
245245+instead need to update the [opam] file, see {{!tip_tool_support_with_opam_dune}
246246+these instructions}.
247247+216248{3:tip_tool_support_with_opam_dune With [opam] and [dune]}
217249218250First make sure your understand the
219251{{!tip_tool_support_with_opam}above basic instructions} for [opam].
220252You then
221221-{{:https://dune.readthedocs.io/en/stable/reference/packages.html#generating-opam-files}need to figure out} how to add the [cmdliner install] instruction to the [build:]
222222-field of the opam file after your [dune] build instructions. For a tool named
223223-[tool] the result should eventually look this:
253253+{{:https://dune.readthedocs.io/en/stable/reference/packages.html#generating-opam-files}
254254+need to add a [.opam.template]} file which inserts the [cmdliner
255255+install] instruction to the [build:] field of the opam file after your
256256+[dune] build instructions. For a tool named [mytool] the
257257+[mytool.opam.template] file should contain:
224258225259{@sh[
226260build: [
227227- [ … ] # Your regular dune build instructions
261261+ # These first two commands are what dune generates if you don't have
262262+ # a template
263263+ ["dune" "subst"] {dev}
264264+ [
265265+ "dune"
266266+ "build"
267267+ "-p"
268268+ name
269269+ "-j"
270270+ jobs
271271+ "@install"
272272+ "@runtest" {with-test}
273273+ "@doc" {with-doc}
274274+ ]
275275+ # This is the important command for cmdliner's files
228276 ["cmdliner" "install" "tool-support"
229277 "--update-opam-install=%{_:name}%.install"
230230- "_build/install/default/bin/tool" {os-family != "windows"}
231231- "_build/install/default/bin/tool.exe" {os-family = "windows"}
278278+ "_build/install/default/bin/mytool" {os-family != "windows"}
279279+ "_build/install/default/bin/mytool.exe" {os-family = "windows"}
232280 "_build/cmdliner-install"]]
233281]}
234282