From 872e4c607453c74413bd63fc08cbc91cb0981db0 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Fri, 31 Jul 2026 14:10:44 +0200 Subject: cli: colitur easter 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. --- bin/main.ml | 30 ++++++++++++++++++++++++++++-- dune-project | 1 + test/cli.t | 21 +++++++++++++++++++++ test/dune | 3 +++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test/cli.t 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 "; + 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 () diff --git a/dune-project b/dune-project index 8a1fa58..cd3af07 100644 --- a/dune-project +++ b/dune-project @@ -1,6 +1,7 @@ (lang dune 3.0) (name colitur) (generate_opam_files true) +(cram enable) (package (name colitur) diff --git a/test/cli.t b/test/cli.t new file mode 100644 index 0000000..319fc8c --- /dev/null +++ b/test/cli.t @@ -0,0 +1,21 @@ +Easter and its Easter-relative movable feasts for a year: + + $ colitur easter 2026 + easter 2026-04-05 + ash-wednesday 2026-02-18 + palm-sunday 2026-03-29 + ascension 2026-05-14 + pentecost 2026-05-24 + corpus-christi 2026-06-04 + +A year outside the supported domain is rejected (exit 2): + + $ colitur easter 1000 + colitur: year 1000 out of range 1583..9999 + [2] + +No/garbage arguments give a usage error (exit 2): + + $ colitur + colitur: usage: colitur easter + [2] diff --git a/test/dune b/test/dune index 3d8df19..8ee8b87 100644 --- a/test/dune +++ b/test/dune @@ -1,3 +1,6 @@ (test (name test_colitur) (libraries colitur_kernel alcotest qcheck qcheck-alcotest)) + +(cram + (deps %{bin:colitur})) -- cgit v1.3