clap subcommands

This commit is contained in:
atagen 2026-03-23 15:11:56 +11:00
parent adea668355
commit a2f207272a
2 changed files with 77 additions and 3 deletions

View file

@ -279,7 +279,15 @@ let process_manpage file =
if is_nushell_builtin cmd then None
else
let result = parse_manpage_string contents in
if result.entries <> [] then Some (cmd, result) else None
let sub_sections = extract_subcommand_sections contents in
let result = if sub_sections <> [] then
{ result with subcommands = List.map (fun (name, desc, _) ->
{ name; desc }) sub_sections }
else result in
let subs = List.map (fun (name, _desc, r) ->
(cmd ^ " " ^ name, r)) sub_sections in
if result.entries <> [] || subs <> [] then Some (cmd, result, subs)
else None
with _ -> None
let manpaged_commands mandir =
@ -499,12 +507,19 @@ let cmd_index bindirs mandirs ignorelist dir =
Array.iter (fun file ->
match process_manpage (Filename.concat subdir file) with
| None -> ()
| Some (cmd, result) ->
| Some (cmd, result, subs) ->
if not (SSet.mem cmd !done_cmds) then begin
write_result ~dir ~source:"manpage" cmd result;
done_cmds := SSet.add cmd !done_cmds;
incr n_results
end
end;
List.iter (fun (sub_cmd, sub_result) ->
if not (SSet.mem sub_cmd !done_cmds) then begin
write_result ~dir ~source:"manpage" sub_cmd sub_result;
done_cmds := SSet.add sub_cmd !done_cmds;
incr n_results
end
) subs
) files
end
) command_sections