1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(*---------------------------------------------------------------------------
Copyright (c) 2011 The cmdliner programmers. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)typeterm_escape=[`Errorofbool*string|`HelpofCmdliner_manpage.format*stringoption]type'aparser=Cmdliner_info.Eval.t->Cmdliner_cline.t->('a,[`Parseofstring|term_escape])resulttype'at=Cmdliner_info.Arg.Set.t*'aparserletconstv=Cmdliner_info.Arg.Set.empty,(fun__->Okv)letapp(args_f,f)(args_v,v)=Cmdliner_info.Arg.Set.unionargs_fargs_v,funeicl->match(feicl)with|Error_ase->e|Okf->matchveiclwith|Error_ase->e|Okv->Ok(fv)letmapfv=app(constf)vletproductv0v1=app(app(const(funxy->(x,y)))v0)v1(*
module Syntax = struct
let ( let+ ) v f = map f v
let ( and+ ) = product
end
*)(* Terms *)let($)=apptype'aret=[`Okof'a|term_escape]letret(al,v)=al,funeicl->matchveiclwith|Ok(`Okv)->Okv|Ok(`Error_aserr)->Errorerr|Ok(`Help_ashelp)->Errorhelp|Error_ase->eletterm_result?(usage=false)(al,v)=al,funeicl->matchveiclwith|Ok(Ok_asok)->ok|Ok(Error(`Msge))->Error(`Error(usage,e))|Error_ase->eletmap_errorf=function|Okx->Okx|Errore->Error(fe)letterm_result'?usaget=letwrap=app(const(map_error(fune->`Msge)))tinterm_result?usagewrapletcli_parse_result(al,v)=al,funeicl->matchveiclwith|Ok(Ok_asok)->ok|Ok(Error(`Msge))->Error(`Parsee)|Error_ase->eletcli_parse_result't=letwrap=app(const(map_error(fune->`Msge)))tincli_parse_resultwrapletmain_name=Cmdliner_info.Arg.Set.empty,(funei_->Ok(Cmdliner_info.Cmd.name@@Cmdliner_info.Eval.mainei))letchoice_names=Cmdliner_info.Arg.Set.empty,(funei_->(* N.B. this keeps everything backward compatible. We return the command
names of main's children *)letnamet=Cmdliner_info.Cmd.nametinletchoices=Cmdliner_info.Cmd.children(Cmdliner_info.Eval.mainei)inOk(List.rev_mapnamechoices))letwith_used_args(al,v):(_*stringlist)t=al,funeicl->matchveiclwith|Okx->letactual_argsarg_infoacc=letargs=Cmdliner_cline.actual_argsclarg_infoinList.rev_appendargsaccinletused=List.rev(Cmdliner_info.Arg.Set.foldactual_argsal[])inOk(x,used)|Error_ase->e