summaryrefslogtreecommitdiff
path: root/2025/ocaml/lib
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-11-29 20:08:11 +0100
committerDJ O'Leary <dijitol@proton.me>2025-11-29 20:09:11 +0100
commit87277098e997661f432be56c27f4b54d51aa9306 (patch)
tree83846830e5102120ef298e8ad9a552b30203fdc6 /2025/ocaml/lib
parent0bf49c4ec799445350c60a96a754e44ac15a2268 (diff)
chore: use updated template
Diffstat (limited to '2025/ocaml/lib')
-rw-r--r--2025/ocaml/lib/application/dune14
-rw-r--r--2025/ocaml/lib/application/logger_sig.mli11
-rw-r--r--2025/ocaml/lib/domain/dune9
-rw-r--r--2025/ocaml/lib/dune3
-rw-r--r--2025/ocaml/lib/infrastructure/dune18
-rw-r--r--2025/ocaml/lib/infrastructure/logger.ml31
-rw-r--r--2025/ocaml/lib/presentation/cli.ml15
-rw-r--r--2025/ocaml/lib/presentation/dune15
8 files changed, 113 insertions, 3 deletions
diff --git a/2025/ocaml/lib/application/dune b/2025/ocaml/lib/application/dune
new file mode 100644
index 0000000..f73f950
--- /dev/null
+++ b/2025/ocaml/lib/application/dune
@@ -0,0 +1,14 @@
+(library
+ (name application)
+ (libraries
+ domain
+ fmt
+ logs)
+ (inline_tests)
+ (preprocess
+ (pps
+ ppx_deriving.show
+ ppx_deriving.eq
+ ppx_deriving.ord
+ ppx_expect))
+ (modules_without_implementation logger_sig))
diff --git a/2025/ocaml/lib/application/logger_sig.mli b/2025/ocaml/lib/application/logger_sig.mli
new file mode 100644
index 0000000..ac84747
--- /dev/null
+++ b/2025/ocaml/lib/application/logger_sig.mli
@@ -0,0 +1,11 @@
+module type Logger = sig
+ val app : string -> unit
+
+ val err : string -> unit
+
+ val warn : string -> unit
+
+ val info : string -> unit
+
+ val debug : string -> unit
+end
diff --git a/2025/ocaml/lib/domain/dune b/2025/ocaml/lib/domain/dune
new file mode 100644
index 0000000..f23b247
--- /dev/null
+++ b/2025/ocaml/lib/domain/dune
@@ -0,0 +1,9 @@
+(library
+ (name domain)
+ (inline_tests)
+ (preprocess
+ (pps
+ ppx_deriving.show
+ ppx_deriving.eq
+ ppx_deriving.ord
+ ppx_expect)))
diff --git a/2025/ocaml/lib/dune b/2025/ocaml/lib/dune
deleted file mode 100644
index 215ce47..0000000
--- a/2025/ocaml/lib/dune
+++ /dev/null
@@ -1,3 +0,0 @@
-(library
- (name advent_of_code_2025)
- (libraries re2 fmt cmdliner))
diff --git a/2025/ocaml/lib/infrastructure/dune b/2025/ocaml/lib/infrastructure/dune
new file mode 100644
index 0000000..9857fbb
--- /dev/null
+++ b/2025/ocaml/lib/infrastructure/dune
@@ -0,0 +1,18 @@
+(library
+ (name infrastructure)
+ (libraries
+ application
+ domain
+ fmt
+ fmt.cli
+ fmt.tty
+ logs
+ logs.cli
+ logs.fmt)
+ (inline_tests)
+ (preprocess
+ (pps
+ ppx_deriving.show
+ ppx_deriving.eq
+ ppx_deriving.ord
+ ppx_expect)))
diff --git a/2025/ocaml/lib/infrastructure/logger.ml b/2025/ocaml/lib/infrastructure/logger.ml
new file mode 100644
index 0000000..d0d37a3
--- /dev/null
+++ b/2025/ocaml/lib/infrastructure/logger.ml
@@ -0,0 +1,31 @@
+module type Configurable_Logger = sig
+ include Application.Logger_sig.Logger
+
+ val configure_logger : level:Logs.level option -> unit
+
+ val parse_level :
+ env:Cmdliner.Cmd.Env.info -> Logs.level option Cmdliner.Term.t
+
+ val configure_renderer : style_renderer:Fmt.style_renderer option -> unit
+end
+
+module CLI_Logger : Configurable_Logger = struct
+ let configure_logger ~level =
+ Logs.set_level level ;
+ Logs.set_reporter (Logs_fmt.reporter ())
+
+ let parse_level ~env = Logs_cli.level ~env ()
+
+ let configure_renderer ~style_renderer =
+ Fmt_tty.setup_std_outputs ?style_renderer ()
+
+ let app msg = Logs.app (fun m -> m "%s" msg)
+
+ let err msg = Logs.err (fun m -> m "%s" msg)
+
+ let warn msg = Logs.warn (fun m -> m "%s" msg)
+
+ let info msg = Logs.info (fun m -> m "%s" msg)
+
+ let debug msg = Logs.debug (fun m -> m "%s" msg)
+end
diff --git a/2025/ocaml/lib/presentation/cli.ml b/2025/ocaml/lib/presentation/cli.ml
new file mode 100644
index 0000000..c306ad2
--- /dev/null
+++ b/2025/ocaml/lib/presentation/cli.ml
@@ -0,0 +1,15 @@
+open Cmdliner
+open Cmdliner.Term.Syntax
+
+let logger () =
+ let env = Cmd.Env.info "LOG_LEVEL" in
+ let+ level = Infrastructure.Logger.CLI_Logger.parse_level ~env
+ and+ style_renderer = Fmt_cli.style_renderer () in
+ Infrastructure.Logger.CLI_Logger.configure_logger ~level ;
+ Fmt_tty.setup_std_outputs ?style_renderer () ;
+ let result_code = 0 in
+ result_code
+
+let cmd = Cmd.v (Cmd.info "tool") @@ logger ()
+
+let run () = Cmd.eval' cmd
diff --git a/2025/ocaml/lib/presentation/dune b/2025/ocaml/lib/presentation/dune
new file mode 100644
index 0000000..a37ca0c
--- /dev/null
+++ b/2025/ocaml/lib/presentation/dune
@@ -0,0 +1,15 @@
+(library
+ (name presentation)
+ (libraries
+ application
+ domain
+ infrastructure
+ cmdliner
+ fmt.cli)
+ (inline_tests)
+ (preprocess
+ (pps
+ ppx_deriving.show
+ ppx_deriving.eq
+ ppx_deriving.ord
+ ppx_expect)))