Add command help

This commit is contained in:
Guillaume 2026-03-14 00:36:20 +01:00
parent c396b3d135
commit 679402b10f

View file

@ -2,6 +2,11 @@ type command = { description : string; run : State.t -> State.t }
module Cmd = Map.Make (String) module Cmd = Map.Make (String)
let show_command state =
let open State in
Printf.printf "[%d]: %s\n" (cursor state) (show_line state);
state
let commands = let commands =
[ [
( "next", ( "next",
@ -9,13 +14,7 @@ let commands =
( "prev", ( "prev",
{ description = "Move cursor to the previous line"; run = State.prev } ); { description = "Move cursor to the previous line"; run = State.prev } );
( "show", ( "show",
{ { description = "Display the current log line"; run = show_command } );
description = "Display the current log line";
run =
(fun s ->
Printf.printf "[%d]: %s\n" (State.cursor s) (State.show_line s);
s);
} );
] ]
|> List.to_seq |> Cmd.of_seq |> List.to_seq |> Cmd.of_seq
@ -24,6 +23,7 @@ let help () =
Cmd.iter Cmd.iter
(fun cmd args -> Printf.printf " %-11s %s\n" cmd args.description) (fun cmd args -> Printf.printf " %-11s %s\n" cmd args.description)
commands; commands;
print_endline " help Show this help";
print_endline " exit, quit Exit the inspector" print_endline " exit, quit Exit the inspector"
let rec loop state = let rec loop state =
@ -34,6 +34,9 @@ let rec loop state =
match cmd with match cmd with
| "" -> loop state | "" -> loop state
| "exit" | "quit" -> print_endline "bye" | "exit" | "quit" -> print_endline "bye"
| "help" ->
help ();
loop state
| _ -> ( | _ -> (
match Cmd.find_opt cmd commands with match Cmd.find_opt cmd commands with
| Some c -> loop (c.run state) | Some c -> loop (c.run state)