builtin_print_help to take its error argument by reference

This fixes a confusing use of pointers.
This commit is contained in:
ridiculousfish 2022-12-31 10:13:03 -08:00
parent 5c216e3d8c
commit 30c708e8a5
3 changed files with 7 additions and 7 deletions

View File

@ -144,14 +144,14 @@ int parse_help_only_cmd_opts(struct help_only_cmd_opts_t &opts, int *optind, int
///
/// Process and print help for the specified builtin or function.
void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name,
wcstring *error_message) {
const wcstring &error_message) {
// This won't ever work if no_exec is set.
if (no_exec()) return;
const wcstring name_esc = escape_string(name);
wcstring cmd = format_string(L"__fish_print_help %ls ", name_esc.c_str());
io_chain_t ios;
if (error_message) {
cmd.append(escape_string(*error_message));
if (!error_message.empty()) {
cmd.append(escape_string(error_message));
// If it's an error, redirect the output of __fish_print_help to stderr
ios.push_back(std::make_shared<io_fd_t>(STDOUT_FILENO, STDERR_FILENO));
}
@ -268,7 +268,7 @@ static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &strea
if (argc != 1) {
wcstring error_message = format_string(BUILTIN_ERR_UNKNOWN, argv[0], argv[1]);
builtin_print_help(parser, streams, argv[0], &error_message);
builtin_print_help(parser, streams, argv[0], error_message);
return STATUS_INVALID_ARGS;
}
@ -284,7 +284,7 @@ static maybe_t<int> builtin_break_continue(parser_t &parser, io_streams_t &strea
}
if (!has_loop) {
wcstring error_message = format_string(_(L"%ls: Not inside of loop\n"), argv[0]);
builtin_print_help(parser, streams, argv[0], &error_message);
builtin_print_help(parser, streams, argv[0], error_message);
return STATUS_CMD_ERROR;
}

View File

@ -88,7 +88,7 @@ const wchar_t *builtin_get_desc(const wcstring &name);
wcstring builtin_help_get(parser_t &parser, const wchar_t *cmd);
void builtin_print_help(parser_t &parser, const io_streams_t &streams, const wchar_t *name,
wcstring *error_message = nullptr);
const wcstring &error_message = {});
int builtin_count_args(const wchar_t *const *argv);
void builtin_unknown_option(parser_t &parser, io_streams_t &streams, const wchar_t *cmd,

View File

@ -27,7 +27,7 @@ static int send_to_bg(parser_t &parser, io_streams_t &streams, job_t *j) {
wcstring error_message = format_string(
_(L"%ls: Can't put job %d, '%ls' to background because it is not under job control\n"),
L"bg", j->job_id(), j->command_wcstr());
builtin_print_help(parser, streams, L"bg", &error_message);
builtin_print_help(parser, streams, L"bg", error_message);
return STATUS_CMD_ERROR;
}