summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-31 14:10:44 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-31 14:10:44 +0200
commit872e4c607453c74413bd63fc08cbc91cb0981db0 (patch)
tree4ecc9e8f84c4eec96943141abe9afa67b6ebc08d
parent58deef45d6039d78bc423554f630d27f6bec1bb3 (diff)
downloadcolitur-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.
-rw-r--r--bin/main.ml30
-rw-r--r--dune-project1
-rw-r--r--test/cli.t21
-rw-r--r--test/dune3
4 files changed, 53 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 ()
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 <year>
+ [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}))