William Leiserson
William Leiserson

Reputation: 155

OCaml Cmdliner non-standard parameters

I'm making an OCaml compiler front-end with Cmdliner, and I want to copy some of the behavior of Clang, such as the "-emit-llvm" option. The code I've got, at present is:

(* Whether to generate LLVM (IR or bitcode) output. *)
let llvm =
  let doc = "In conjunction with -S or -c, generate LLVM output instead of
             native output.  For an object file, this means LLVM bitcode (.bc)
             will be generated, and for assembly it will be LLVM IR (.ll)."
  in
  let emit_llvm = Arg.info ["emit-llvm"] ~doc in
  Arg.(value & flag emit_llvm)

This creates the option "--emit-llvm" with 2 leading dashes, but it isn't clear how to do it with just 1. Is this possible?

Upvotes: 1

Views: 160

Answers (2)

Daniel Bünzli
Daniel Bünzli

Reputation: 5167

Since Cmdliner can parse short flag groups (à la tar -xvf, see the end of this section) this would become too ambiguous. Besides Cmdliner, following GNU's conventions, does indeed mandate two dashes for long options.

What you can do however is to take your Sys.argv and patch a selection of single dash options you might recognise by pre-prending them with a single dash before giving the result explictitely to Term.eval via the optional argv argument.

Upvotes: 4

Étienne Millon
Étienne Millon

Reputation: 3028

According to the documentation, strings of length 1 map to short options (with a single dash), and others to long options (with two dashes). So as of cmdliner.1.0.2, this is not possible.

Upvotes: 3

Related Questions