fix partial, systemctl manpage

This commit is contained in:
atagen 2026-03-23 22:01:46 +11:00
parent 71de2e7b4b
commit 76eb2c2aef
4 changed files with 176 additions and 12 deletions

View file

@ -625,23 +625,31 @@ let cmd_complete spans user_dir system_dirs =
| Some _ as found -> (found, partial)
| None -> (None, partial) in
let found, partial = resolve lookup_tokens last_token in
(* If not found at all, try on-the-fly resolution for the base command *)
(* Try on-the-fly resolution when no match or only a parent matched *)
let n_lookup = List.length lookup_tokens in
let result, partial = match found with
| Some _ -> (found, partial)
| None ->
| Some (_, _, depth) when depth >= n_lookup - 1 ->
(* Exact or near-exact match — use it *)
(found, partial)
| _ ->
(* No match, or only a parent matched — try on-the-fly resolution *)
(match find_in_path cmd_name with
| Some path ->
(match resolve_and_cache ~dir:user_dir cmd_name path with
| Some _pairs -> resolve lookup_tokens last_token
| None -> (None, partial))
| None -> (None, partial)) in
| None -> (found, partial))
| None -> (found, partial)) in
let candidates = match result with
| None -> []
| Some (_matched_name, r, _depth) ->
| Some (_matched_name, r, depth) ->
(* When the match is shallower than requested, the user already
typed a subcommand beyond the matched level don't show
sibling subcommands, only flags *)
let sub_candidates = if depth < n_lookup - 1 then [] else
let subs = match r.subcommands with
| _ :: _ -> r.subcommands
| [] -> subcommands_of dirs _matched_name in
let sub_candidates = List.filter_map (fun (sc : subcommand) ->
List.filter_map (fun (sc : subcommand) ->
let s = fuzzy_score partial sc.name in
if s > 0 then Some (s, completion_json sc.name sc.desc) else None
) subs in