summaryrefslogtreecommitdiff
path: root/ocaml/lib/presentation
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2026-06-26 18:04:09 +0200
committerDJ O'Leary <dijitol@proton.me>2026-06-26 18:04:09 +0200
commit6d8fb621d1e93b83786890d6d9cb6f0d8defa8ae (patch)
tree17c90d3984c114aa023600cc5bec6f6004b02243 /ocaml/lib/presentation
parentad4ea5ca4bc9f7540ee1d6a4fa2d881709dc6459 (diff)
refactor!: invert repo directory structure
now is language first
Diffstat (limited to 'ocaml/lib/presentation')
-rw-r--r--ocaml/lib/presentation/cli.ml62
-rw-r--r--ocaml/lib/presentation/dune16
2 files changed, 78 insertions, 0 deletions
diff --git a/ocaml/lib/presentation/cli.ml b/ocaml/lib/presentation/cli.ml
new file mode 100644
index 0000000..7864e7f
--- /dev/null
+++ b/ocaml/lib/presentation/cli.ml
@@ -0,0 +1,62 @@
+(* Business logic behind CLI *)
+
+let run_solver name solver filepath =
+ let content = Infrastructure.File.read filepath in
+ match solver content () with
+ | Error msg ->
+ Logs.app (fun m -> m "[%s] Err=%s" name msg)
+ | Ok answer ->
+ Logs.app (fun m -> m "[%s] ANSWER=%d" name answer)
+
+let run_day _ = function
+ | 1 ->
+ let filepath = "../_input/day_01.txt" in
+ run_solver "D01P01" Application.D01p01.solve filepath ;
+ run_solver "D01P02" Application.D01p02.solve filepath ;
+ 0
+ | 2 ->
+ let filepath = "../_input/day_02.txt" in
+ run_solver "D02P01" Application.D02p01.solve filepath ;
+ run_solver "D02P02" Application.D02p02.solve filepath ;
+ 0
+ | 3 ->
+ let filepath = "../_input/day_03.txt" in
+ run_solver "D03P01" Application.D03p01.solve filepath ;
+ run_solver "D03P02" Application.D03p02.solve filepath ;
+ 0
+ | 4 ->
+ let filepath = "../_input/day_04.txt" in
+ run_solver "D04P01" Application.D04p01.solve filepath ;
+ run_solver "D04P02" Application.D04p02.solve filepath ;
+ 0
+ | 5 ->
+ let filepath = "../_input/day_05.txt" in
+ run_solver "D05P01" Application.D05p01.solve filepath ;
+ 0
+ | 6 ->
+ let filepath = "../_input/day_06.txt" in
+ run_solver "D06P01" Application.D06p01.solve filepath ;
+ run_solver "D06P02" Application.D06p02.solve filepath ;
+ 0
+ | _ ->
+ 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
+ Arg.(value & pos 0 int 1 & info [] ~docv:"DAY" ~doc)
+
+let day_t = Term.(const run_day $ setup_log_t $ day_arg)
+
+let cmd =
+ let info = Cmd.info "aoc" ~version:"0.1.0" in
+ Cmd.v info day_t
+
+let run () = Cmd.eval' cmd
diff --git a/ocaml/lib/presentation/dune b/ocaml/lib/presentation/dune
new file mode 100644
index 0000000..ae1fcb1
--- /dev/null
+++ b/ocaml/lib/presentation/dune
@@ -0,0 +1,16 @@
+(library
+ (name presentation)
+ (libraries
+ application
+ domain
+ infrastructure
+ cmdliner
+ fmt.cli
+ fmt.tty)
+ (inline_tests)
+ (preprocess
+ (pps
+ ppx_deriving.show
+ ppx_deriving.eq
+ ppx_deriving.ord
+ ppx_expect)))