123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162(*
* Copyright (c) 2014 David Sheets <sheets@alum.mit.edu>
*
* 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.
*)openCmdliner(* The order of the argument sections in the manpage can be enforced in the call to [with_argv] *)lets_net="NETWORK OPTIONS"lets_dns="DNS OPTIONS"lets_he="HAPPY EYEBALLS OPTIONS"lets_ssh="SSH OPTIONS"lets_tls="TLS OPTIONS"lets_http="HTTP OPTIONS"lets_log="LOG AND MONITORING OPTIONS"lets_disk="DISK OPTIONS"lets_ocaml="OCAML RUNTIME OPTIONS"typelog_threshold=[`All|`Srcofstring]*Logs.leveloption(* We provisionally record backtraces until the [backtrace] runtime argument
further below is evaluated. This ensures we get proper backtraces if someone
calls [register_arg _ ()] too early before command line arguments are
evaluated. *)let()=Printexc.record_backtracetrueletset_level~defaultl=letsrcs=Logs.Src.list()inletdefault=trysnd@@List.find(function`All,_->true|_->false)lwithNot_found->defaultinLogs.set_leveldefault;List.iter(function|`All,_->()|`Srcsrc,level->(trylets=List.find(funs->Logs.Src.names=src)srcsinLogs.Src.set_levelslevelwithNot_found->Format.printf"WARNING: %s is not a valid log source.\n%!"src))lmoduleConv=structletlog_threshold=letparserstr=letlevelsrcs=Result.bind(Logs.level_of_strings)(funl->Ok(src,l))inmatchString.split_on_char':'strwith|[_]->level`Allstr|["*";lvl]->level`Alllvl|[src;lvl]->level(`Srcsrc)lvl|_->Error(`Msg("Can't parse log threshold: "^str))inletserializeppf=function|`All,l->Format.pp_print_stringppf(Logs.level_to_stringl)|`Srcs,l->Format.fprintfppf"%s:%s"s(Logs.level_to_stringl)inArg.conv(parser,serialize)endletlogs=letenum=List.map(funv->(Logs.level_to_stringv,v))Logs.[None;SomeApp;SomeError;SomeWarning;SomeInfo;SomeDebug]inletdocs=s_loginletlogs=Arg.listConv.log_thresholdinletdoc=Printf.sprintf"Be more or less verbose. $(docv) must be of the form \
$(b,*:info,foo:debug) means that that the log threshold is set to \
$(b,info) for every log sources but the $(b,foo) which is set to \
$(b,debug). The log level must be %s."(Arg.doc_alts_enumenum)inletdoc=Arg.info~docv:"LEVEL"~doc~docs["l";"logs"]inArg.(value&optlogs[]doc)(** {3 Blocks} *)letdisk=letdoc=Arg.info~docs:s_disk~doc:"Name of the docteur disk (for Solo5 targets, the name must contains \
only alpanumeric characters)."["disk"]inArg.(value&optstring"disk"doc)letanalyze=letdoc=Arg.info~docs:s_disk~doc:"Analyze at the boot time the given docteur disk."["analyze"]inArg.(value&optbooltruedoc)(** {3 Initial delay} *)letdelay=letdoc=Arg.info~docs:Cmdliner.Manpage.s_common_options~doc:"Delay n seconds before starting up"["delay"]inArg.(value&optint0doc)(* Hooks *)letexit_hooks=ref[]letenter_iter_hooks=ref[]letleave_iter_hooks=ref[]letrunt=List.iter(funf->f())!tletaddft=t:=f::!tletrun_exit_hooks()=Lwt_list.iter_s(funhook->Lwt.catch(fun()->hook())(fun_->Lwt.return_unit))!exit_hooksletrun_enter_iter_hooks()=runenter_iter_hooksletrun_leave_iter_hooks()=runleave_iter_hooksletat_exitf=addfexit_hooksletat_leave_iterf=addfleave_iter_hooksletat_enter_iterf=addfenter_iter_hooksletwith_argv=Functoria_runtime.with_argv~sections:[Manpage.s_arguments;Manpage.s_options;s_http;s_ssh;s_tls;s_he;s_dns;s_net;s_log;s_disk;s_ocaml;]letruntime_args=Functoria_runtime.runtime_argsletregister=Functoria_runtime.register_argletregister_arg=Functoria_runtime.register_argletargument_error=Functoria_runtime.argument_errorlethelp_version=Functoria_runtime.help_version