Typesense_auth.CmdCmdliner helpers for Typesense CLI authentication.
This module provides reusable command-line argument definitions and command builders for authentication workflows. It supports multiple profiles for managing multiple server connections.
(* In your main.ml *)
Eio_main.run @@ fun env ->
let fs = env#fs in
Cmd.group (Cmd.info "typesense-cli")
[ Typesense_auth.Cmd.auth_cmd env fs
; (* other commands *)
]
|> Cmd.eval_exnTYPESENSE_SERVER: Default server URLTYPESENSE_API_KEY: Default API keyUses Logs_cli for verbosity control:
-v or --verbose: Info level logging-v -v or --verbosity=debug: Debug level logging--verbose-http: Enable verbose HTTP protocol loggingval server_arg : string Cmdliner.Term.tRequired positional argument for server URL (also reads TYPESENSE_SERVER).
val server_opt : string option Cmdliner.Term.tOptional --server argument (also reads TYPESENSE_SERVER).
val api_key_arg : string option Cmdliner.Term.tOptional --api-key argument (also reads TYPESENSE_API_KEY).
val profile_arg : string option Cmdliner.Term.tOptional --profile argument for selecting a specific profile.
val setup_logging :
(Fmt.style_renderer option * Logs.level option) Cmdliner.Term.tTerm that collects logging options (-v, --color, etc.). Use with setup_logging_with_config to apply logging after parsing.
val setup_logging_with_config :
Fmt.style_renderer option ->
Logs.level option ->
Requests.Cmd.config ->
unitsetup_logging_with_config style_renderer level config sets up logging with the given options. Extracts --verbose-http from the requests config. Call this at the start of command execution.
val requests_config_term :
Eio.Fs.dir_ty Eio.Path.t ->
Requests.Cmd.config Cmdliner.Term.tTerm for HTTP request configuration (timeouts, retries, proxy, etc.).
Commands take an env parameter from the outer Eio_main.run context, and an fs path for building cmdliner terms.
val auth_cmd :
< fs : Eio.Fs.dir_ty Eio.Path.t
; clock : _ Eio.Time.clock
; net : _ Eio.Net.t.. > ->
Eio.Fs.dir_ty Eio.Path.t ->
unit Cmdliner.Cmd.tComplete auth command group combining login, logout, status, and profile.
val with_session :
?profile:string ->
(Eio.Fs.dir_ty Eio.Path.t -> Session.t -> 'a) ->
< fs : Eio.Fs.dir_ty Eio.Path.t.. > ->
'awith_session ?profile f env loads the session and calls f fs session. Prints an error and exits if not logged in.
val with_client :
?requests_config:Requests.Cmd.config ->
?profile:string ->
(Eio.Fs.dir_ty Eio.Path.t -> Client.t -> 'a) ->
< fs : Eio.Fs.dir_ty Eio.Path.t
; clock : _ Eio.Time.clock
; net : _ Eio.Net.t.. > ->
'awith_client ?requests_config ?profile f env loads the session, creates a client, and calls f fs client. Prints an error and exits if not logged in.
These types and functions allow other programs to easily use Typesense profiles that were set up with the typesense CLI.
module Profile_config : sig ... endConfiguration for using a Typesense profile.
val profile_config_term :
Eio.Fs.dir_ty Eio.Path.t ->
Profile_config.t Cmdliner.Term.tCmdliner term that collects all configuration needed to use a Typesense profile.
Combines:
-v, --color, etc.)--verbose-http)--profile)Use with with_client to create an authenticated client.