fix builtin help ignoring redirects (#10276)

* fix builtin help ignoring redirects

* test builtin help redirects
This commit is contained in:
Samuel Collins 2024-02-03 00:53:50 +01:00 committed by GitHub
parent b265152fba
commit 508ea59dcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

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::{IoChain, IoFd, OutputStream};
use crate::io::{IoFd, OutputStream};
use crate::parse_constants::UNKNOWN_BUILTIN_ERR_MSG;
use crate::parse_util::parse_util_argument_is_help;
use crate::parser::{Block, BlockType, LoopStatus};
@ -553,7 +553,7 @@ pub fn builtin_print_help_error(
}
let name_esc = escape(cmd);
let mut cmd = sprintf!("__fish_print_help %ls ", &name_esc);
let mut ios = IoChain::new();
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

View File

@ -0,0 +1,15 @@
# RUN: %fish %s
# Test redirecting builtin help with a pipe
set -lx __fish_data_dir (mktemp -d)
mkdir -p $__fish_data_dir/man/man1
# Create $__fish_data_dir/man/man1/and.1
echo '.\" Test manpage for and (not real).
.TH "AND" "1" "Feb 02, 2024" "3.7" "fish-shell"
.SH NAME
and \- conditionally execute a command' >$__fish_data_dir/man/man1/and.1
# help should be redirected to grep instead of appearing on STDOUT
builtin and --help | grep -q "and - conditionally execute a command"
echo $status
#CHECK: 0