123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687(* YOCaml a static blog generator.
Copyright (C) 2024 The Funkyworkers and The YOCaml's developers
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. *)typevalue=Pathof{watched:bool;path:Path.t}|Stringofstringtypearg=|Flagof{prefix:string;name:string}|Paramof{prefix:string;suffix:stringoption;name:string;value:value}|Plainofvaluetypet={command:string;args:arglist}letparam_to_string=function|Strings->s|Path{path;_}->Path.to_stringpathletarg_to_string=function|Flag{prefix;name}->[prefix^name]|Param{prefix;suffix=Somesuffix;name;value}->[prefix^name^suffix^param_to_stringvalue]|Param{prefix;suffix=None;name;value}->[prefix^name;param_to_stringvalue]|Plainvalue->[param_to_stringvalue]letargs_to_stringargs=args|>List.concat_maparg_to_stringletflag?(prefix="-")name=Flag{prefix;name}letparam?(prefix="--")?suffixnamevalue=Param{prefix;suffix;name;value}letargx=Plainxletstringvalue=Stringvalueletintvalue=string(string_of_intvalue)letcharvalue=string(String.make1value)letfloatvalue=string(string_of_floatvalue)letboolvalue=string(string_of_boolvalue)letlist?(sep=" ")xs=xs|>String.concatsep|>stringletpath?(watched=false)path=Path{watched;path}letwatchedx=path~watched:truexletmakecommandargs={command;args}lets=stringleti=intletc=charletf=floatletp=pathletw=watchedletto_string{command;args}=command^" "^(args_to_stringargs|>String.concat" ")letppppfcmd=Format.fprintfppf"%s"(to_stringcmd)letpp_argppfarg=Format.fprintfppf"%a"(Format.pp_print_list~pp_sep:(funppf()->Format.fprintfppf" ")Format.pp_print_string)(arg_to_stringarg)letdeps_of{args;_}=List.filter_map(function|Plain(Path{watched=true;path})|Param{value=Path{watched=true;path};_}->Somepath|_->None)argsletnormalize{command;args}=(command,args_to_stringargs)