diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-12-03 21:24:53 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-12-03 21:24:53 +0100 |
| commit | de813901748af4ba4d52aa193f0e6bcff9e27c8b (patch) | |
| tree | c134c4f86306528e0aa2a2f1b19fe4998563b157 /2025/ocaml | |
| parent | 4efc4e08ae62945002d35404c108e8c724da0cb3 (diff) | |
refactor(2025): update cli output to include colour
Diffstat (limited to '2025/ocaml')
| -rw-r--r-- | 2025/ocaml/lib/presentation/cli.ml | 22 | ||||
| -rw-r--r-- | 2025/ocaml/lib/presentation/dune | 3 |
2 files changed, 18 insertions, 7 deletions
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 |
