diff --git a/src/builtins/fish_indent.rs b/src/builtins/fish_indent.rs index 2cfe6f8b4..f4830a0f8 100644 --- a/src/builtins/fish_indent.rs +++ b/src/builtins/fish_indent.rs @@ -939,15 +939,19 @@ fn throwing_main() -> i32 { let args: Vec = std::env::args_os() .map(|osstr| bytes2wcstring(osstr.as_bytes())) .collect(); - do_indent(&mut streams, args).builtin_status_code() + do_indent(None, &mut streams, args).builtin_status_code() } -pub fn fish_indent(_parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> BuiltinResult { +pub fn fish_indent(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> BuiltinResult { let args = args.iter_mut().map(|x| x.to_owned()).collect(); - do_indent(streams, args) + do_indent(Some(parser), streams, args) } -fn do_indent(streams: &mut IoStreams, args: Vec) -> BuiltinResult { +fn do_indent( + parser: Option<&Parser>, + streams: &mut IoStreams, + args: Vec, +) -> BuiltinResult { // Types of output we support #[derive(Eq, PartialEq)] enum OutputType { @@ -987,7 +991,11 @@ enum OutputType { match c { 'P' => DUMP_PARSE_TREE.store(true), 'h' => { - print_help("fish_indent"); + if let Some(parser) = parser { + builtin_print_help(parser, streams, L!("fish_indent")); + } else { + print_help("fish_indent"); + } return Ok(SUCCESS); } 'v' => { diff --git a/src/builtins/fish_key_reader.rs b/src/builtins/fish_key_reader.rs index 3f5e386f1..09ed0ff3b 100644 --- a/src/builtins/fish_key_reader.rs +++ b/src/builtins/fish_key_reader.rs @@ -172,6 +172,7 @@ fn setup_and_process_keys( } fn parse_flags( + parser: Option<&Parser>, streams: &mut IoStreams, args: Vec, continuous_mode: &mut bool, @@ -184,7 +185,6 @@ fn parse_flags( wopt(L!("version"), ArgType::NoArgument, 'v'), wopt(L!("verbose"), ArgType::NoArgument, 'V'), ]; - let mut shim_args: Vec<&wstr> = args.iter().map(|s| s.as_ref()).collect(); let mut w = WGetopter::new(short_opts, long_opts, &mut shim_args); while let Some(opt) = w.next_opt() { @@ -193,7 +193,11 @@ fn parse_flags( *continuous_mode = true; } 'h' => { - print_help("fish_key_reader"); + if let Some(parser) = parser { + builtin_print_help(parser, streams, L!("fish_key_reader")); + } else { + print_help("fish_key_reader"); + } return ControlFlow::Break(Ok(SUCCESS)); } 'v' => { @@ -239,7 +243,7 @@ fn parse_flags( } pub fn fish_key_reader( - _parser: &Parser, + parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr], ) -> BuiltinResult { @@ -247,7 +251,13 @@ pub fn fish_key_reader( let mut verbose = false; let args = args.iter_mut().map(|x| x.to_owned()).collect(); - if let ControlFlow::Break(s) = parse_flags(streams, args, &mut continuous_mode, &mut verbose) { + if let ControlFlow::Break(s) = parse_flags( + Some(parser), + streams, + args, + &mut continuous_mode, + &mut verbose, + ) { return s; } @@ -300,7 +310,7 @@ fn throwing_main() -> i32 { .map(|osstr| bytes2wcstring(osstr.as_bytes())) .collect(); if let ControlFlow::Break(s) = - parse_flags(&mut streams, args, &mut continuous_mode, &mut verbose) + parse_flags(None, &mut streams, args, &mut continuous_mode, &mut verbose) { return s.builtin_status_code(); } diff --git a/tests/checks/indent.fish b/tests/checks/indent.fish index 1881d6b12..b2303cabb 100644 --- a/tests/checks/indent.fish +++ b/tests/checks/indent.fish @@ -656,3 +656,9 @@ printf %s\n a b c | builtin fish_indent | grep b # Regression test that fish_indent doesn't panic with closed stdin. fish_indent <&- # CHECKERR: fish_indent: stdin is closed + +function __fish_print_help + echo Help using PATH[1]=$PATH[1] +end +PATH=hello fish_indent --help +# CHECK: Help using PATH[1]=hello