Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file Optslog.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108(* Similar to https://github.com/dbuenzli/logs/blob/master/src/logs_cli.ml
but with a (IMHO: saner) default of INFO and conventionally named
"--log-level" options. *)openCmdlinerletstrf=Format.asprintf(** [level_arg level] is the command line argument [ARG] of [--log-level ARG]
that matches the log level [level]. *)letlevel_arg=function|Logs.App|Error->"ERROR"|Warning->"WARNING"|Info->"INFO"|Debug->"DEBUG"letreclast_of_listhdtl=matchtlwith[]->hd|hd'::tl'->last_of_listhd'tl'(** [level ?env ?docs ?debug_opt ?short_opts ()] is the cmdliner {!Cmdliner.Term.t}
for the logging options.
By default the ["--log-level"] and ["--quiet"] options are added.
Provide the [env] argument if there should be an environment variable
for the ["--log-level"] option.
Use the flag [~debug_opt:()] to add a ["--debug"] option that will
enable debug logs.
Use the flag [~short_opts:()] to add ["-l"] and ["-q"] options that
are aliases of the ["--log-level"] and ["--quiet"] options, respectively.
*)letlevel?env?docs?debug_opt?short_opts()=letdebug_t=matchdebug_optwith|None->Term.constfalse|Some()->letdoc=Printf.sprintf"Enable debug logs. Takes precedence over %s."(matchshort_optswith|None->"the $(b,--log-level) option"|Some()->"$(b,-l) and $(b,--log-level) options")inArg.(value&flag&info["debug"]~doc?docs)inletlog_level_t=letenum=[(* The first entry is the default. Aka it is a hack for the option's absent rendering *)("INFO",None);(* ("QUIET", Some None); *)("ERROR",Some(SomeLogs.Error));("WARNING",Some(SomeLogs.Warning));("INFO",Some(SomeLogs.Info));("DEBUG",Some(SomeLogs.Debug));]inletlog_level=Arg.enumenuminletenum_alts=Arg.doc_alts_enumList.(tlenum)inletdoc=strf"Set the verbosity of log messages. If the option is repeated the last \
$(docv) is used. $(docv) must be %s."enum_altsinletnames=matchshort_optswith|None->["log-level"]|Some()->["l";"log-level"]inlett=Arg.(value&opt_alllog_level[]&info?env~docv:"LEVEL"~doc?docsnames)inTerm.(const(fun(lst:Logs.leveloptionoptionlist)->matchlstwith|[]->None|hd::tl->matchlast_of_listhdtlwith|(loo:Logs.leveloptionoption)->Option.joinloo)$t)inletquiet_t=letdoc=Printf.sprintf"Be quiet. Takes precedence over %s."(match(debug_opt,short_opts)with|None,None->"the $(b,--log-level) option"|None,Some()->"$(b,-l) and $(b,--log-level) options"|Some(),None->"$(b,--debug) and $(b,--log-level) options"|Some(),Some()->"$(b,--debug), $(b,-l) and $(b,--log-level) options")inletnames=matchshort_optswithNone->["quiet"]|Some()->["q";"quiet"]inArg.(value&flag&info~doc?docsnames)inletchoosequietlog_leveldebug=ifquietthenNoneelseifdebugthenSomeLogs.Debugelsematchlog_levelwith|Somelog_level->Somelog_level|None->SomeLogs.InfoinTerm.(constchoose$quiet_t$log_level_t$debug_t)