__fish_print_help: remove error message

__fish_print_help supports printing an error message above the
documentation.

This is currently only used by extremely rare edge cases, namely:

	eval "break"
	eval "continue --unknown"
	fish -c 'sleep 10&; bg %1'

Let's remove this feature to enable us to use man directly (#11786).
This commit is contained in:
Johannes Altmanninger
2025-09-19 15:09:21 +02:00
parent 26116b477e
commit d422ad603e
5 changed files with 24 additions and 49 deletions

View File

@@ -1,4 +1,5 @@
function __fish_print_help --description "Print help message for the specified fish function or builtin" --argument-names item error_message
function __fish_print_help --description "Print help message for the specified fish function or builtin"
set -l item $argv[1]
switch $item
case !
set item not
@@ -75,7 +76,6 @@ function __fish_print_help --description "Print help message for the specified f
set -l state blank
set -l have_name
begin
string join \n $error_message
for line in $help
# categorize the line
set -l line_type

View File

@@ -14,17 +14,13 @@ fn send_to_bg(
{
let jobs = parser.jobs();
if !jobs[job_pos].wants_job_control() {
let err = {
let job = &jobs[job_pos];
wgettext_fmt!(
"%ls: Can't put job %s, '%ls' to background because it is not under job control\n",
cmd,
job.job_id().to_wstring(),
job.command()
)
};
drop(jobs);
builtin_print_help_error(parser, streams, cmd, &err);
let job = &jobs[job_pos];
streams.err.append(wgettext_fmt!(
"%ls: Can't put job %s, '%ls' to background because it is not under job control\n",
cmd,
job.job_id().to_wstring(),
job.command()
));
return Err(STATUS_CMD_ERROR);
}

View File

@@ -1,7 +1,7 @@
use super::prelude::*;
use crate::builtins::*;
use crate::common::{escape, get_by_sorted_name, str2wcstring, Named};
use crate::io::{IoFd, OutputStream};
use crate::io::OutputStream;
use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG;
use crate::parse_util::parse_util_argument_is_help;
use crate::parser::{Block, BlockType, LoopStatus};
@@ -9,12 +9,11 @@
use crate::reader::reader_read;
use crate::wchar::L;
use errno::errno;
use libc::{STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO};
use libc::STDIN_FILENO;
use std::fs::File;
use std::io::{BufRead, BufReader, Read};
use std::os::fd::FromRawFd;
use std::sync::Arc;
pub type BuiltinCmd = fn(&Parser, &mut IoStreams, &mut [&wstr]) -> BuiltinResult;
@@ -627,28 +626,13 @@ pub fn builtin_get_desc(name: &wstr) -> Option<&'static wstr> {
///
/// Process and print help for the specified builtin or function.
pub fn builtin_print_help(parser: &Parser, streams: &mut IoStreams, cmd: &wstr) {
builtin_print_help_error(parser, streams, cmd, L!(""))
}
pub fn builtin_print_help_error(
parser: &Parser,
streams: &mut IoStreams,
cmd: &wstr,
error_message: &wstr,
) {
// This won't ever work if no_exec is set.
if no_exec() {
return;
}
let name_esc = escape(cmd);
let mut cmd = sprintf!("__fish_print_help %ls ", &name_esc);
let mut ios = streams.io_chain.clone();
if !error_message.is_empty() {
cmd.push_utfstr(&escape(error_message));
// If it's an error, redirect the output of __fish_print_help to stderr
ios.push(Arc::new(IoFd::new(STDOUT_FILENO, STDERR_FILENO)));
}
let res = parser.eval(&cmd, &ios);
let cmd = sprintf!("__fish_print_help %ls ", &name_esc);
let res = parser.eval(&cmd, streams.io_chain);
if res.status.normal_exited() && res.status.exit_code() == 2 {
streams
.err
@@ -986,8 +970,9 @@ fn builtin_break_continue(
}
if argc != 1 {
let error_message = wgettext_fmt!(BUILTIN_ERR_UNKNOWN, argv[0], argv[1]);
builtin_print_help_error(parser, streams, argv[0], &error_message);
streams
.err
.append(wgettext_fmt!(BUILTIN_ERR_UNKNOWN, argv[0], argv[1]));
return Err(STATUS_INVALID_ARGS);
}
@@ -1004,8 +989,9 @@ fn builtin_break_continue(
}
}
if !has_loop {
let error_message = wgettext_fmt!("%ls: Not inside of loop\n", argv[0]);
builtin_print_help_error(parser, streams, argv[0], &error_message);
streams
.err
.append(wgettext_fmt!("%ls: Not inside of loop\n", argv[0]));
return Err(STATUS_CMD_ERROR);
}

View File

@@ -431,16 +431,12 @@ end
# Check that these error correctly.
$dyn_break
eval break
#CHECKERR: Error-message: break: Not inside of loop
#CHECKERR: Documentation for break
#CHECKERR: Error-message: break: Not inside of loop
#CHECKERR: Documentation for break
#CHECKERR: break: Not inside of loop
#CHECKERR: break: Not inside of loop
$dyn_continue
eval continue
#CHECKERR: Error-message: continue: Not inside of loop
#CHECKERR: Documentation for continue
#CHECKERR: Error-message: continue: Not inside of loop
#CHECKERR: Documentation for continue
#CHECKERR: continue: Not inside of loop
#CHECKERR: continue: Not inside of loop
break -h
#CHECKERR: Documentation for break

View File

@@ -1,7 +1,4 @@
function __fish_print_help
if set -q argv[2]
echo Error-message: $argv[2] >&2
end
echo Documentation for $argv[1] >&2
echo Documentation for $argv >&2
return 1
end