diff --git a/bin/main.ml b/bin/main.ml index e56a02d..57b4bf6 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -56,6 +56,7 @@ Usage: List indexed commands. inshellah manpage FILE Parse a manpage and emit nushell extern inshellah manpage-dir DIR Batch-process manpages under DIR + inshellah completions Generate nushell completions for inshellah |}; exit 1 @@ -1167,6 +1168,86 @@ let parse_dir_args args = | first :: rest -> (first, rest) in (user_dir, system_dirs, List.rev rest_args) +(* "inshellah completions nushell" — emit native nushell extern for inshellah itself *) +let cmd_completions_nushell () = + let result = { + entries = []; + subcommands = []; + positionals = []; + description = "nushell completions engine"; + } in + let index_result = { + entries = [ + { switch = Long "dir"; param = Some (Mandatory "PATH"); desc = "output directory for cached completions" }; + { switch = Long "ignore"; param = Some (Mandatory "FILE"); desc = "skip listed commands entirely" }; + { switch = Long "help-only"; param = Some (Mandatory "FILE"); desc = "skip manpages for listed commands, use --help instead" }; + ]; + subcommands = []; + positionals = [ + { pos_name = "prefix"; optional = false; variadic = true }; + ]; + description = "index completions from prefix directories"; + } in + let complete_result = { + entries = [ + { switch = Long "dir"; param = Some (Mandatory "PATH"); desc = "colon-separated cache paths" }; + ]; + subcommands = []; + positionals = [ + { pos_name = "cmd"; optional = false; variadic = false }; + { pos_name = "args"; optional = true; variadic = true }; + ]; + description = "nushell custom completer, outputs JSON candidates"; + } in + let query_result = { + entries = [ + { switch = Long "dir"; param = Some (Mandatory "PATH"); desc = "colon-separated cache paths" }; + ]; + subcommands = []; + positionals = [ + { pos_name = "cmd"; optional = false; variadic = false }; + ]; + description = "print stored completion data for a command"; + } in + let dump_result = { + entries = [ + { switch = Long "dir"; param = Some (Mandatory "PATH"); desc = "colon-separated cache paths" }; + ]; + subcommands = []; + positionals = []; + description = "list indexed commands"; + } in + let manpage_result = { + entries = []; + subcommands = []; + positionals = [ + { pos_name = "file"; optional = false; variadic = false }; + ]; + description = "parse a manpage and emit nushell extern"; + } in + let manpage_dir_result = { + entries = []; + subcommands = []; + positionals = [ + { pos_name = "dir"; optional = false; variadic = false }; + ]; + description = "batch-process manpages under a directory"; + } in + let completions_result = { + entries = []; + subcommands = []; + positionals = []; + description = "generate nushell completions for inshellah"; + } in + print_string (generate_extern "inshellah" result); + print_string (generate_extern "inshellah index" index_result); + print_string (generate_extern "inshellah complete" complete_result); + print_string (generate_extern "inshellah query" query_result); + print_string (generate_extern "inshellah dump" dump_result); + print_string (generate_extern "inshellah manpage" manpage_result); + print_string (generate_extern "inshellah manpage-dir" manpage_dir_result); + print_string (generate_extern "inshellah completions" completions_result) + (* --- entry point --- * dispatch on the first argument to the appropriate subcommand handler. *) let () = @@ -1193,4 +1274,5 @@ let () = cmd_dump (user_dir :: system_dirs) | ["manpage"; file] -> cmd_manpage file | ["manpage-dir"; dir] -> cmd_manpage_dir dir + | ["completions"] -> cmd_completions_nushell () | _ -> usage ()