diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-31 14:10:44 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-07-31 14:10:44 +0200 |
| commit | 872e4c607453c74413bd63fc08cbc91cb0981db0 (patch) | |
| tree | 4ecc9e8f84c4eec96943141abe9afa67b6ebc08d /bin/main.ml | |
| parent | 58deef45d6039d78bc423554f630d27f6bec1bb3 (diff) | |
| download | colitur-872e4c607453c74413bd63fc08cbc91cb0981db0.tar.gz colitur-872e4c607453c74413bd63fc08cbc91cb0981db0.zip | |
cli: colitur easter <year> prints Easter and its anchors
Argv-parsed subcommand; validates the 1583..9999 domain (exit 2 otherwise);
prints 'name YYYY-MM-DD' lines. Cram test covers the output and the exit codes.
Diffstat (limited to 'bin/main.ml')
| -rw-r--r-- | bin/main.ml | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/bin/main.ml b/bin/main.ml index 761f68e..eb70a26 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -1,2 +1,28 @@ -(* colitur CLI — scaffold stub; the real `easter` subcommand arrives in Task 4. *) -let () = () +module D = Colitur_kernel.Date +module C = Colitur_kernel.Computus + +let fmt d = Printf.sprintf "%04d-%02d-%02d" (D.year d) (D.month d) (D.day d) + +let easter_report y = + [ ("easter", C.gregorian_easter y); + ("ash-wednesday", C.ash_wednesday y); + ("palm-sunday", C.palm_sunday y); + ("ascension", C.ascension y); + ("pentecost", C.pentecost y); + ("corpus-christi", C.corpus_christi y) ] + |> List.iter (fun (name, d) -> Printf.printf "%s %s\n" name (fmt d)) + +let usage () = + prerr_endline "colitur: usage: colitur easter <year>"; + exit 2 + +let () = + match Sys.argv with + | [| _; "easter"; ys |] -> ( + match int_of_string_opt ys with + | Some y when y >= 1583 && y <= 9999 -> easter_report y + | Some y -> + Printf.eprintf "colitur: year %d out of range 1583..9999\n" y; + exit 2 + | None -> usage ()) + | _ -> usage () |
