this repo has no description

Cmdlinerise

+1
dune-project
···
cid
ppx_repr
irmin-fs
+
cmdliner
)
(tags
("shell")))
+1
shelter.opam
···
"cid"
"ppx_repr"
"irmin-fs"
+
"cmdliner"
"odoc" {with-doc}
]
build: [
+37 -8
src/bin/main.ml
···
Eio.Path.mkdirs ~exists_ok:true ~perm:0o755 path;
path
+
(* Command Line *)
+
open Cmdliner
+
+
let main =
+
let run config =
+
Eio_posix.run @@ fun env ->
+
let dir = state_dir env#fs "shelter" in
+
Shelter.main config env#fs env#clock env#process_mgr dir
+
in
+
let t = Term.(const run $ Shelter_main.config_term) in
+
let man =
+
[
+
`P
+
"Shelter is a shell session shim to help control uncertainty when \
+
working from the terminal";
+
]
+
in
+
let doc = "Shelter: version-controlled shell sessions" in
+
let info = Cmd.info ~man ~doc "main" in
+
(Cmd.v info t, t, info)
+
+
let passthrough =
+
let run config =
+
Eio_posix.run @@ fun env ->
+
let dir = state_dir env#fs "passthrough" in
+
Pass.main config env#fs env#clock env#process_mgr dir
+
in
+
let t = Term.(const run $ Shelter_passthrough.config_term) in
+
let info = Cmd.info "passthrough" in
+
Cmd.v info t
+
+
let cmds =
+
let cmd, term, info = main in
+
let cmds = [ cmd; passthrough ] in
+
Cmd.group ~default:term info cmds
+
let () =
-
Eio_posix.run @@ fun env ->
Fmt_tty.setup_std_outputs ();
-
match Sys.argv.(1) with
-
| "passthrough" ->
-
let dir = state_dir env#fs "passthrough" in
-
Pass.main env#fs env#clock env#process_mgr dir
-
| _ | (exception Invalid_argument _) ->
-
let dir = state_dir env#fs "shelter" in
-
Shelter.main env#fs env#clock env#process_mgr dir
+
exit (Cmd.eval cmds)
+1 -1
src/lib/dune
···
(library
(name shelter)
(public_name shelter)
-
(libraries irmin-fs.unix eio.unix eio linenoise void repr))
+
(libraries cmdliner irmin-fs.unix eio.unix eio linenoise void repr))
+7
src/lib/engine.ml
···
module type S = sig
+
type config
+
(** A configuration *)
+
+
val config_term : config Cmdliner.Term.t
+
(** A cmdliner term for constructing a config *)
+
type action
(** An action to run *)
···
to setup history completions etc. with LNoise. *)
val run :
+
config ->
_ Eio.Path.t ->
_ Eio.Time.clock ->
Eio_unix.Process.mgr_ty Eio_unix.Process.mgr ->
+5 -1
src/lib/passthrough/shelter_passthrough.ml
···
open Eio
+
type config = unit
+
+
let config_term = Cmdliner.Term.const ()
+
type action = Exec of string [@@deriving repr]
let action = action_t
···
in
List.iter (fun v -> LNoise.history_add v |> ignore) entries
-
let run _fs clock proc
+
let run (() : config) _fs clock proc
( ((Shelter.History.Store ((module S), store) : entry Shelter.History.t) as
full_store),
() ) (Exec command) =
+4 -4
src/lib/shelter.ml
···
module Make (H : History.S) (Engine : Engine.S with type entry = H.t) = struct
module Store = Irmin_fs_unix.KV.Make (H)
-
let run fs clock proc store =
+
let run config fs clock proc store =
let store = History.Store ((module Store), store) in
let initial_ctx = Engine.init fs proc store in
let rec loop store ctx exit_code =
···
| None -> ()
| Some input -> (
let action = Engine.action_of_command input in
-
match Engine.run fs clock proc (store, ctx) action with
+
match Engine.run config fs clock proc (store, ctx) action with
| Error (Eio.Process.Child_error exit_code) ->
Fmt.epr "%a\n%!" Eio.Process.pp_status exit_code;
loop store ctx exit_code
···
in
loop store initial_ctx (`Exited 0)
-
let main fs clock proc directory =
+
let main config fs clock proc directory =
Irmin_fs.run directory @@ fun () ->
let conf = Irmin_fs.config (Eio.Path.native_exn directory) in
let repo = Store.Repo.v conf in
let store = Store.main repo in
-
run fs clock proc store
+
run config fs clock proc store
end
+15
src/lib/shelter/config.ml
···
+
type t = { no_diffing : bool; no_ebpf : bool }
+
+
let cmdliner =
+
let open Cmdliner in
+
let no_diffing =
+
let doc = "Disable diffing." in
+
Arg.(value & flag & info [ "no-diffing" ] ~doc)
+
in
+
let no_ebpf =
+
let doc = "Disable eBPF." in
+
Arg.(value & flag & info [ "no-ebpf" ] ~doc)
+
in
+
Term.(
+
const (fun no_diffing no_ebpf -> { no_diffing; no_ebpf })
+
$ no_diffing $ no_ebpf)
+6 -2
src/lib/shelter/shelter_main.ml
···
let merge = Irmin.Merge.(default (Repr.option t))
end
+
type config = Config.t
+
+
let config_term = Config.cmdliner
+
type entry = History.t
type action =
···
(list s);
store
-
let run _fs clock _proc (((H.Store ((module S), store) : entry H.t) as s), ctx)
-
= function
+
let run (_config : config) _fs clock _proc
+
(((H.Store ((module S), store) : entry H.t) as s), ctx) = function
| Set_mode mode ->
with_latest ~default:(fun _ -> Ok (s, ctx)) s @@ fun (_, entry) ->
commit ~message:"mode change" clock s { entry with mode };