123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195open!Importletnames_to_string_humnames=Nonempty_list.to_listnames|>List.map~f:Name.to_string_with_dashes|>String.concat~sep:",";;moduleParse_error=structtypet=|Arg_lacks_paramofName.t|Flag_has_paramof{name:Name.t;value:string}|No_such_argofName.t|Name_would_begin_with_dashofstring|Short_name_would_be_dashof{entire_short_sequence:string}|Short_name_used_with_dash_dashofName.t|Pos_req_missingofint|Named_req_missingofName.tNonempty_list.t|Named_opt_appeared_multiple_timesof(Name.tNonempty_list.t*int)|Named_req_appeared_multiple_timesof(Name.tNonempty_list.t*int)|Flag_appeared_multiple_timesof(Name.tNonempty_list.t*int)|Conv_failedof{locator:[`NamedofName.t|`Positionalofint]option;message:string}|Too_many_positional_argumentsof{max:int;first_excess_argument:string}|Invalid_char_in_argument_nameof{attempted_argument_name:string;invalid_char:char}|No_such_subcommandofstringletto_string=function|Arg_lacks_paramname->sprintf"Named argument %S lacks parameter."(Name.to_string_with_dashesname)|Flag_has_param{name;value}->sprintf"Flag %s does not take a parameter but was passed: %S"(Name.to_string_with_dashesname)value|No_such_argname->sprintf"Unknown argument name: %s"(Name.to_string_with_dashesname)|Name_would_begin_with_dashstring->sprintf"%S is not a valid argument specifier as it begins with 3 dashes. Only a single \
dash or two dashes may be used to denote an argument."string|Short_name_would_be_dash{entire_short_sequence}->sprintf"Encountered dash while parsing sequence of short names \"-%s\". Each character \
in a sequence of short names is interpreted as a short name, but dashes may not \
be used as short names."entire_short_sequence|Short_name_used_with_dash_dashname->sprintf"Single-character names must only be specified with a single dash. \"--%s\" is \
not allowed as it has two dashes but only one character."(Name.to_stringname)|Pos_req_missingi->sprintf"Missing required positional argument at position %d."i|Named_req_missingnames->sprintf"Missing required named argument: %s"(names_to_string_humnames)|Named_opt_appeared_multiple_times(names,n)->sprintf"The option %S was passed %d times but may only appear at most once."(names_to_string_humnames)n|Named_req_appeared_multiple_times(names,n)->sprintf"The argument %S was passed %d times but must be passed exactly once."(names_to_string_humnames)n|Flag_appeared_multiple_times(names,n)->sprintf"The flag %S was passed %d times but must may only appear at most once."(names_to_string_humnames)n|Conv_failed{locator;message}->(matchlocatorwith|Some(`Namedname)->sprintf"Failed to parse the argument to %S: %s"(Name.to_string_with_dashesname)message|Some(`Positionali)->sprintf"Failed to parse the argument at position %d: %s"imessage|None->sprintf"Failed to parse the argument: %s"message)|Too_many_positional_arguments{max=0;first_excess_argument}->sprintf"This command does not accept any positional arguments. First excess argument: %S"first_excess_argument|Too_many_positional_arguments{max;first_excess_argument}->sprintf"Too many positional arguments. At most %d positional arguments may be passed. \
First excess argument: %S"maxfirst_excess_argument|Invalid_char_in_argument_name{attempted_argument_name;invalid_char}->sprintf"Invalid character %C in argument name %S"invalid_charattempted_argument_name|No_such_subcommandsubcommand->sprintf"No such subcommand: %S"subcommand;;letexit_code=124endmoduleSpec_error=structtypet=|Empty_name_list|Duplicate_nameofName.t|Invalid_nameof(string*Name.Invalid.t)|Negative_positionofint|Duplicate_enum_namesofstringlist|No_such_enum_valueof{valid_names:stringlist}|Gap_in_positional_argument_rangeofint|Name_reserved_for_helpofName.t|Positional_argument_collision_with_different_value_namesof{index:int;value_name1:string;value_name2:string}|Conflicting_requiredness_for_positional_argumentofint|Duplicate_command_namesofstringlistletto_string=function|Empty_name_list->"Name list is empty"|Duplicate_namename->sprintf"The name %S is used in multiple arguments."(Name.to_string_with_dashesname)|Invalid_name(attempted_name,invalid)->letreason=matchinvalidwith|Name.Invalid.Begins_with_dash->"it begins with a dash"|Empty_name->"it is the empty string"|Invalid_charchar->sprintf"it contains the character %C"charinsprintf"Attempted to use %S as an argument name. %S is not a valid argument name \
because %s which is not allowed."attempted_nameattempted_namereason|Negative_positioni->sprintf"Attempted to declare positional argument with negative position: %d"i|Duplicate_enum_namesnames->sprintf"An enum was declared with duplicate names. The following names were duplicated: \
%s"(String.concat~sep:" "names)|No_such_enum_value{valid_names}->sprintf"Attempted to format an enum value as a string but the value does not appear in \
the enum declaration. Valid names for this enum are: %s"(String.concat~sep:" "valid_names)|Gap_in_positional_argument_rangei->sprintf"Attempted to declare a parser with a gap in its positional arguments. No parser \
would interpret the argument at position %d but there is a parser for at least \
one argument at a higher position."i|Name_reserved_for_helpname->sprintf"The name %S can't be used as it's reserved for printing help messages."(Name.to_string_with_dashesname)|Positional_argument_collision_with_different_value_names{index;value_name1;value_name2}->sprintf"The positional argument with index %d was defined multiple times with different \
value names: %S and %S"indexvalue_name1value_name2|Conflicting_requiredness_for_positional_argumentindex->sprintf"Multiple positional arguments registered at the same index (%d) with different \
requiredness"index|Duplicate_command_namesnames->sprintf"Duplicate command names: %s"(String.concat~sep:", "names);;endletspec_errorerror=raise(Failure(Printf.sprintf"Error in argument spec: %s"(Spec_error.to_stringerror)));;