From de813901748af4ba4d52aa193f0e6bcff9e27c8b Mon Sep 17 00:00:00 2001 From: DJ O'Leary Date: Wed, 3 Dec 2025 21:24:53 +0100 Subject: refactor(2025): update cli output to include colour --- 2025/ocaml/lib/presentation/cli.ml | 22 ++++++++++++++++------ 2025/ocaml/lib/presentation/dune | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to '2025/ocaml/lib/presentation') diff --git a/2025/ocaml/lib/presentation/cli.ml b/2025/ocaml/lib/presentation/cli.ml index 29195b6..6f5a548 100644 --- a/2025/ocaml/lib/presentation/cli.ml +++ b/2025/ocaml/lib/presentation/cli.ml @@ -1,9 +1,11 @@ +(* Business logic behind CLI *) + let run_solver name solver filepath = let content = Infrastructure.File.read filepath in let answer = solver content () in Logs.app (fun m -> m "%s=%d" name answer) -let run_day = function +let run_day _ = function | 1 -> let filepath = "../_input/day_01.txt" in run_solver "D01P01" Application.D01p01.solve filepath ; @@ -17,14 +19,22 @@ let run_day = function | _ -> failwith "day not implemented" +(* Command line interface *) + +open Cmdliner + +let setup_log style_renderer = Fmt_tty.setup_std_outputs ?style_renderer () + +let setup_log_t = Term.(const setup_log $ Fmt_cli.style_renderer ()) + let day_arg = let doc = "Day to run. MUST be in range of 1-12." in - Cmdliner.Arg.(value & pos 0 int 1 & info [] ~docv:"DAY" ~doc) + Arg.(value & pos 0 int 1 & info [] ~docv:"DAY" ~doc) -let day_t = Cmdliner.Term.(const run_day $ day_arg) +let day_t = Term.(const run_day $ setup_log_t $ day_arg) let cmd = - let info = Cmdliner.Cmd.info "aoc" ~version:"0.1.0" in - Cmdliner.Cmd.v info day_t + let info = Cmd.info "aoc" ~version:"0.1.0" in + Cmd.v info day_t -let run () = Cmdliner.Cmd.eval' cmd +let run () = Cmd.eval' cmd diff --git a/2025/ocaml/lib/presentation/dune b/2025/ocaml/lib/presentation/dune index a37ca0c..ae1fcb1 100644 --- a/2025/ocaml/lib/presentation/dune +++ b/2025/ocaml/lib/presentation/dune @@ -5,7 +5,8 @@ domain infrastructure cmdliner - fmt.cli) + fmt.cli + fmt.tty) (inline_tests) (preprocess (pps -- cgit v1.2.3