From d422ad603ee85f8eff4b9d7700c2d614557775de Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Fri, 19 Sep 2025 15:09:21 +0200 Subject: [PATCH] __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). --- share/functions/__fish_print_help.fish | 4 +-- src/builtins/bg.rs | 18 +++++------ src/builtins/shared.rs | 34 ++++++--------------- tests/checks/basic.fish | 12 +++----- tests/test_functions/__fish_print_help.fish | 5 +-- 5 files changed, 24 insertions(+), 49 deletions(-) diff --git a/share/functions/__fish_print_help.fish b/share/functions/__fish_print_help.fish index 9b891f78f..dc15b816e 100644 --- a/share/functions/__fish_print_help.fish +++ b/share/functions/__fish_print_help.fish @@ -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 diff --git a/src/builtins/bg.rs b/src/builtins/bg.rs index 17fba323c..74b5379c5 100644 --- a/src/builtins/bg.rs +++ b/src/builtins/bg.rs @@ -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); } diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index 011afb4c3..682597149 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -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); } diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 1f2ca879a..178659fee 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -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 diff --git a/tests/test_functions/__fish_print_help.fish b/tests/test_functions/__fish_print_help.fish index 0ecc5daab..926644091 100644 --- a/tests/test_functions/__fish_print_help.fish +++ b/tests/test_functions/__fish_print_help.fish @@ -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