···9898 f fs client
9999 ) env
100100101101+(* Profile configuration for external programs *)
102102+103103+module Profile_config = struct
104104+ type t = {
105105+ style_renderer : Fmt.style_renderer option;
106106+ log_level : Logs.level option;
107107+ requests_config : Requests.Cmd.config;
108108+ profile : string option;
109109+ }
110110+111111+ let style_renderer t = t.style_renderer
112112+ let log_level t = t.log_level
113113+ let requests_config t = t.requests_config
114114+ let profile t = t.profile
115115+116116+ let setup_logging t =
117117+ setup_logging_with_config t.style_renderer t.log_level t.requests_config
118118+end
119119+120120+let profile_config_term fs =
121121+ let make (sr, ll) rc p =
122122+ Profile_config.{ style_renderer = sr; log_level = ll; requests_config = rc; profile = p }
123123+ in
124124+ Term.(const make $ setup_logging $ requests_config_term fs $ profile_arg)
125125+101126(* Login command *)
102127103128let login_action ~requests_config ~server ~api_key ~email ~password ~profile ~key_name env =
+62
ocaml-immich/lib/cmd.mli
···115115 [f fs client]. Prints an error and exits if not logged in.
116116 @param requests_config HTTP request configuration
117117 @param profile Profile to load (default: current profile) *)
118118+119119+(** {1 Profile Configuration for External Programs}
120120+121121+ These types and functions allow other programs to easily use Immich profiles
122122+ that were set up with the immich CLI. This provides a single cmdliner term
123123+ that bundles all the necessary configuration.
124124+125125+ {2 Example Usage}
126126+127127+ {[
128128+ (* In your sortal/bin/main.ml *)
129129+ open Cmdliner
130130+131131+ let my_cmd env fs =
132132+ let doc = "My command using Immich" in
133133+ let info = Cmd.info "my-command" ~doc in
134134+ let action config =
135135+ let open Immich_auth.Cmd.Profile_config in
136136+ setup_logging config;
137137+ Immich_auth.Cmd.with_client
138138+ ~requests_config:(requests_config config)
139139+ ?profile:(profile config)
140140+ (fun _fs client ->
141141+ let api = Immich_auth.Client.client client in
142142+ (* Use the Immich API here *)
143143+ ()
144144+ ) env
145145+ in
146146+ Cmd.v info Term.(const action $ Immich_auth.Cmd.profile_config_term fs)
147147+ ]} *)
148148+149149+(** Configuration for using an Immich profile. *)
150150+module Profile_config : sig
151151+ type t
152152+ (** Bundled configuration for Immich profile access. *)
153153+154154+ val style_renderer : t -> Fmt.style_renderer option
155155+ (** Terminal style renderer setting. *)
156156+157157+ val log_level : t -> Logs.level option
158158+ (** Logging level. *)
159159+160160+ val requests_config : t -> Requests.Cmd.config
161161+ (** HTTP request configuration. *)
162162+163163+ val profile : t -> string option
164164+ (** Selected profile name, if any. *)
165165+166166+ val setup_logging : t -> unit
167167+ (** [setup_logging config] initializes logging with the bundled settings.
168168+ Call this at the start of your command execution. *)
169169+end
170170+171171+val profile_config_term : Eio.Fs.dir_ty Eio.Path.t -> Profile_config.t Term.t
172172+(** Cmdliner term that collects all configuration needed to use an Immich profile.
173173+174174+ Combines:
175175+ - Logging options ([-v], [--color], etc.)
176176+ - HTTP configuration (timeouts, retries, proxy, [--verbose-http])
177177+ - Profile selection ([--profile])
178178+179179+ Use with {!with_client} to create an authenticated client. *)