12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788(*
* Copyright (c) 2015 Gabriel Radanne <drupyog@zoho.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)letruntime_args_r=ref[]letruntime_args()=!runtime_args_rmoduleArg=structtype'at={arg:'aCmdliner.Term.t;mutablevalue:'aoption}letcreatearg={arg;value=None}letgett=matcht.valuewith|None->invalid_arg"Called too early. Please delay this call to after the start \
function of the unikernel."|Somev->vletterm(typea)(t:at)=letsetw=t.value<-SomewinCmdliner.Term.(constset$t.arg)endletinitialized=reffalseletregister_argt=if!initializedtheninvalid_arg"The function register_arg was called to late. Please call register_arg \
before the start function is executed (e.g. in a top-level binding).";letu=Arg.createtinruntime_args_r:=Arg.termu::!runtime_args_r;fun()->Arg.getuletregister=register_arglethelp_version=63letargument_error=64letwith_argv?sectionskeyssargv=letopenCmdlinerinif!initializedthen()elseletgatherkrest=Term.(const(fun()()->())$k$rest)inlett=List.fold_rightgatherkeys(Term.const())inletexits=[Cmd.Exit.info~doc:"on success."Cmd.Exit.ok;Cmd.Exit.info~doc:"on Solo5 internal error."1;Cmd.Exit.info~doc:"on showing this help."help_version;Cmd.Exit.info~doc:"on any argument parsing error."argument_error;Cmd.Exit.info~doc:"on unexpected internal errors (bugs) while processing the boot \
parameters."Cmd.Exit.internal_error;Cmd.Exit.info~doc:"on OCaml uncaught exception."255;]inletman=Option.map(List.map(funs->`Ss))sectionsinmatchCmd.(eval_value~argv(Cmd.v(info?man~exitss)t))with|Ok(`Ok_)->initialized:=true;()|Error`Parse->exitargument_error|Error`Term->print_endline"Hint: To pass a space, it needs to be escaped twice: \
\027[1m--hello='Hello,\\ world!'\027[m";print_endline" Another possibility is: \027[1m--hello='\"Hello, \
world!\"'\027[m";exitargument_error|Error`Exn->exitCmd.Exit.internal_error|Ok`Help|Ok`Version->exithelp_version