1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283(**************************************************************************)(* *)(* Copyright 2020 David Allsopp Ltd. *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)openOpamCompattypet=int*intletsupported_versions=[(2,0);(2,1)]letis_supportedv=List.memvsupported_versionsletof_strings=matchString.indexs'.'with|iwhens.[0]<>'0'&&(i>=String.lengths-2||s.[i+1]<>'0')->begintryScanf.sscanfs"%u.%u%!"(funmajorminor->(major,minor))withScanf.Scan_failure_->failwith"OpamVersion.CLI.of_string"end|exceptionNot_found->failwith"OpamVersion.CLI.of_string"|_->failwith"OpamVersion.CLI.of_string"letcurrent=of_string@@OpamVersion.(to_stringcurrent_nopatch)(* This line is checked on CI to ensure that default cli version
matches release opam version *)letdefault=(2,0)letof_string_opts=trySome(of_strings)withFailure_->Noneletto_string(major,minor)=Printf.sprintf"%d.%d"majorminorletto_jsonv=`String(to_stringv)letof_json=function|`Stringx->of_string_optx|_->Nonelet(>=)=Stdlib.(>=)let(<)=Stdlib.(<)letcompare=Stdlib.compareletpreviouscli=letfpreviousversion=ifversion>previous&&cli>versionthenversionelsepreviousinletzero=(0,0)inletprevious=List.fold_leftfzerosupported_versionsinifprevious=zerothenraiseNot_foundelseprevious(* CLI version extended with provenance *)moduleSourced=structtypenonrect=t*OpamStateTypes.provenanceletcurrent=current,`Defaultletenvs=OpamStd.Option.Op.(s>>=of_string_opt>>|(func->c,`Env))endmoduleOp=structlet(@>=)(c,_)=Stdlib.(>=)clet(@<)(c,_)=Stdlib.(<)clet(@=)(c,_)=Stdlib.(=)cendmoduleO=structtypenonrect=tletto_string=to_stringletto_json=to_jsonletof_json=of_jsonletcompare=compareendmoduleSet=OpamStd.Set.Make(O)moduleMap=OpamStd.Map.Make(O)