···9393 in
9494 Cmd.v info term
95959696+let version_cmd =
9797+ let doc = "Print version information about the Public Suffix List data" in
9898+ let info = Cmd.info "version" ~doc in
9999+ let term =
100100+ Term.(const (fun (version, commit) ->
101101+ Printf.printf "Version: %s\n" version;
102102+ Printf.printf "Commit: %s\n" commit)
103103+ $ Publicsuffix_cmd.version_term (psl ()))
104104+ in
105105+ Cmd.v info term
106106+96107let default_cmd =
97108 let doc = "Query the Public Suffix List" in
98109 let sdocs = Manpage.s_common_options in
···105116 registrable_section_cmd;
106117 suffix_section_cmd;
107118 stats_cmd;
119119+ version_cmd;
108120 ]
109121110122let () = exit (Cmd.eval default_cmd)
+42-7
gen/gen_psl.ml
···126126 let rule_count = ref 0 in
127127 let icann_count = ref 0 in
128128 let private_count = ref 0 in
129129+ let version = ref None in
130130+ let commit = ref None in
129131 (* Helper to check if string contains substring *)
130132 let contains_substring s sub =
131133 try
···133135 true
134136 with Not_found -> false
135137 in
138138+ (* Helper to extract value after "KEY: " pattern *)
139139+ let extract_value line prefix =
140140+ let prefix_len = String.length prefix in
141141+ if String.length line > prefix_len &&
142142+ String.sub line 0 prefix_len = prefix then
143143+ Some (String.trim (String.sub line prefix_len (String.length line - prefix_len)))
144144+ else
145145+ None
146146+ in
136147 try
137148 while true do
138149 let line = input_line ic in
150150+ (* Check for version and commit info *)
151151+ if !version = None then
152152+ version := extract_value line "// VERSION: ";
153153+ if !commit = None then
154154+ commit := extract_value line "// COMMIT: ";
139155 (* Check for section markers *)
140156 if contains_substring line "===BEGIN ICANN DOMAINS===" then
141157 current_section := ICANN
···149165 else incr private_count
150166 ) (parse_line !current_section line)
151167 done;
152152- (trie, !rule_count, !icann_count, !private_count)
168168+ (trie, !rule_count, !icann_count, !private_count, !version, !commit)
153169 with End_of_file ->
154170 close_in ic;
155155- (trie, !rule_count, !icann_count, !private_count)
171171+ (trie, !rule_count, !icann_count, !private_count, !version, !commit)
156172157173(** Escape a string for OCaml source code *)
158174let escape_string s =
···172188 Buffer.contents b
173189174190(** Generate OCaml code for the trie *)
175175-let generate_code trie rule_count icann_count private_count =
191191+let generate_code trie rule_count icann_count private_count version commit =
176192 (* Print header *)
177193 print_string {|(* Auto-generated from public_suffix_list.dat - DO NOT EDIT *)
178194(* This file contains the parsed Public Suffix List as OCaml data structures *)
···191207}
192208193209|};
194194- Printf.printf "(* Statistics: %d total rules (%d ICANN, %d private) *)\n\n"
210210+ Printf.printf "(* Statistics: %d total rules (%d ICANN, %d private) *)\n"
195211 rule_count icann_count private_count;
212212+ Printf.printf "(* Version: %s *)\n" version;
213213+ Printf.printf "(* Commit: %s *)\n" commit;
214214+ print_string "\n";
196215197216 (* Generate the trie as nested let bindings using a depth-first traversal *)
198217 let node_counter = ref 0 in
···280299|};
281300 Printf.printf "let rule_count = %d\n\n" rule_count;
282301 Printf.printf "let icann_rule_count = %d\n\n" icann_count;
283283- Printf.printf "let private_rule_count = %d\n" private_count
302302+ Printf.printf "let private_rule_count = %d\n\n" private_count;
303303+ (* Generate version and commit values *)
304304+ Printf.printf "let version = %S\n\n" version;
305305+ Printf.printf "let commit = %S\n" commit
284306285307let () =
286308 if Array.length Sys.argv < 2 then begin
···288310 exit 1
289311 end;
290312 let filename = Sys.argv.(1) in
291291- let trie, rule_count, icann_count, private_count = parse_file filename in
292292- generate_code trie rule_count icann_count private_count
313313+ let trie, rule_count, icann_count, private_count, version, commit = parse_file filename in
314314+ (* Ensure version and commit are present *)
315315+ let version = match version with
316316+ | Some v -> v
317317+ | None ->
318318+ Printf.eprintf "ERROR: VERSION not found in %s\n" filename;
319319+ exit 1
320320+ in
321321+ let commit = match commit with
322322+ | Some c -> c
323323+ | None ->
324324+ Printf.eprintf "ERROR: COMMIT not found in %s\n" filename;
325325+ exit 1
326326+ in
327327+ generate_code trie rule_count icann_count private_count version commit
···4444val stats_term : Publicsuffix.t -> (int * int * int) Cmdliner.Term.t
4545(** Term that returns statistics about the Public Suffix List as a tuple of
4646 (total_rules, icann_rules, private_rules). *)
4747+4848+val version_term : Publicsuffix.t -> (string * string) Cmdliner.Term.t
4949+(** Term that returns version information about the Public Suffix List as a tuple of
5050+ (version, commit). *)
···263263264264(** Number of private section rules *)
265265val private_rule_count : t -> int
266266+267267+(** {1 Version Information} *)
268268+269269+(** Version string from the embedded PSL data.
270270+271271+ Returns the version identifier from the Public Suffix List source file,
272272+ typically in the format ["YYYY-MM-DD_HH-MM-SS_UTC"].
273273+*)
274274+val version : t -> string
275275+276276+(** Commit hash from the embedded PSL data.
277277+278278+ Returns the git commit hash from the Public Suffix List repository
279279+ corresponding to the version of the data embedded in this library.
280280+*)
281281+val commit : t -> string
+20
lib/publicsuffix_data.mli
···159159 allow subdomain registration.
160160*)
161161val private_rule_count : int
162162+163163+(** {1 Version Information}
164164+165165+ These values reflect the version and commit information from the PSL
166166+ data at the time this module was generated.
167167+*)
168168+169169+(** Version string from the PSL data file.
170170+171171+ This is the version identifier from the Public Suffix List source file,
172172+ typically in the format "YYYY-MM-DD_HH-MM-SS_UTC".
173173+*)
174174+val version : string
175175+176176+(** Commit hash from the PSL data file.
177177+178178+ This is the git commit hash from the Public Suffix List repository
179179+ corresponding to the version of the data embedded in this library.
180180+*)
181181+val commit : string