···1515 Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 path;
1616 path
17171818+(* Command Line *)
1919+open Cmdliner
2020+2121+let main =
2222+ let run config =
2323+ Eio_posix.run @@ fun env ->
2424+ let dir = state_dir env#fs "shelter" in
2525+ Shelter.main config env#fs env#clock env#process_mgr dir
2626+ in
2727+ let t = Term.(const run $ Shelter_main.config_term) in
2828+ let man =
2929+ [
3030+ `P
3131+ "Shelter is a shell session shim to help control uncertainty when \
3232+ working from the terminal";
3333+ ]
3434+ in
3535+ let doc = "Shelter: version-controlled shell sessions" in
3636+ let info = Cmd.info ~man ~doc "main" in
3737+ (Cmd.v info t, t, info)
3838+3939+let passthrough =
4040+ let run config =
4141+ Eio_posix.run @@ fun env ->
4242+ let dir = state_dir env#fs "passthrough" in
4343+ Pass.main config env#fs env#clock env#process_mgr dir
4444+ in
4545+ let t = Term.(const run $ Shelter_passthrough.config_term) in
4646+ let info = Cmd.info "passthrough" in
4747+ Cmd.v info t
4848+4949+let cmds =
5050+ let cmd, term, info = main in
5151+ let cmds = [ cmd; passthrough ] in
5252+ Cmd.group ~default:term info cmds
5353+1854let () =
1919- Eio_posix.run @@ fun env ->
2055 Fmt_tty.setup_std_outputs ();
2121- match Sys.argv.(1) with
2222- | "passthrough" ->
2323- let dir = state_dir env#fs "passthrough" in
2424- Pass.main env#fs env#clock env#process_mgr dir
2525- | _ | (exception Invalid_argument _) ->
2626- let dir = state_dir env#fs "shelter" in
2727- Shelter.main env#fs env#clock env#process_mgr dir
5656+ exit (Cmd.eval cmds)
···11module type S = sig
22+ type config
33+ (** A configuration *)
44+55+ val config_term : config Cmdliner.Term.t
66+ (** A cmdliner term for constructing a config *)
77+28 type action
39 (** An action to run *)
410···2026 to setup history completions etc. with LNoise. *)
21272228 val run :
2929+ config ->
2330 _ Eio.Path.t ->
2431 _ Eio.Time.clock ->
2532 Eio_unix.Process.mgr_ty Eio_unix.Process.mgr ->
+5-1
src/lib/passthrough/shelter_passthrough.ml
···11open Eio
2233+type config = unit
44+55+let config_term = Cmdliner.Term.const ()
66+37type action = Exec of string [@@deriving repr]
4859let action = action_t
···3337 in
3438 List.iter (fun v -> LNoise.history_add v |> ignore) entries
35393636-let run _fs clock proc
4040+let run (() : config) _fs clock proc
3741 ( ((Shelter.History.Store ((module S), store) : entry Shelter.History.t) as
3842 full_store),
3943 () ) (Exec command) =
+4-4
src/lib/shelter.ml
···44module Make (H : History.S) (Engine : Engine.S with type entry = H.t) = struct
55 module Store = Irmin_fs_unix.KV.Make (H)
6677- let run fs clock proc store =
77+ let run config fs clock proc store =
88 let store = History.Store ((module Store), store) in
99 let initial_ctx = Engine.init fs proc store in
1010 let rec loop store ctx exit_code =
···1313 | None -> ()
1414 | Some input -> (
1515 let action = Engine.action_of_command input in
1616- match Engine.run fs clock proc (store, ctx) action with
1616+ match Engine.run config fs clock proc (store, ctx) action with
1717 | Error (Eio.Process.Child_error exit_code) ->
1818 Fmt.epr "%a\n%!" Eio.Process.pp_status exit_code;
1919 loop store ctx exit_code
···2424 in
2525 loop store initial_ctx (`Exited 0)
26262727- let main fs clock proc directory =
2727+ let main config fs clock proc directory =
2828 Irmin_fs.run directory @@ fun () ->
2929 let conf = Irmin_fs.config (Eio.Path.native_exn directory) in
3030 let repo = Store.Repo.v conf in
3131 let store = Store.main repo in
3232- run fs clock proc store
3232+ run config fs clock proc store
3333end
+15
src/lib/shelter/config.ml
···11+type t = { no_diffing : bool; no_ebpf : bool }
22+33+let cmdliner =
44+ let open Cmdliner in
55+ let no_diffing =
66+ let doc = "Disable diffing." in
77+ Arg.(value & flag & info [ "no-diffing" ] ~doc)
88+ in
99+ let no_ebpf =
1010+ let doc = "Disable eBPF." in
1111+ Arg.(value & flag & info [ "no-ebpf" ] ~doc)
1212+ in
1313+ Term.(
1414+ const (fun no_diffing no_ebpf -> { no_diffing; no_ebpf })
1515+ $ no_diffing $ no_ebpf)
+6-2
src/lib/shelter/shelter_main.ml
···2323 let merge = Irmin.Merge.(default (Repr.option t))
2424end
25252626+type config = Config.t
2727+2828+let config_term = Config.cmdliner
2929+2630type entry = History.t
27312832type action =
···168172 (list s);
169173 store
170174171171-let run _fs clock _proc (((H.Store ((module S), store) : entry H.t) as s), ctx)
172172- = function
175175+let run (_config : config) _fs clock _proc
176176+ (((H.Store ((module S), store) : entry H.t) as s), ctx) = function
173177 | Set_mode mode ->
174178 with_latest ~default:(fun _ -> Ok (s, ctx)) s @@ fun (_, entry) ->
175179 commit ~message:"mode change" clock s { entry with mode };