From 87c73b7fbfd66d62be6606eefd388e26820698a0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 17 Sep 2025 14:49:24 +0200 Subject: [PATCH] builtin break/continue: support -h/--help argument These are not generic builtins because we check whether they're inside a loop. There's no reason to not support "break -h" when we support "if -h" etc.; do that. --- doc_src/cmds/break.rst | 2 +- doc_src/cmds/continue.rst | 2 ++ src/builtins/shared.rs | 7 +++++++ tests/checks/basic.fish | 9 +++++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/doc_src/cmds/break.rst b/doc_src/cmds/break.rst index 5b401ffbc..0f58753b1 100644 --- a/doc_src/cmds/break.rst +++ b/doc_src/cmds/break.rst @@ -19,7 +19,7 @@ Description ``break`` halts a currently running loop (*LOOP_CONSTRUCT*), such as a :doc:`for ` or :doc:`while ` loop. It is usually added inside of a conditional block such as an :doc:`if ` block. -There are no parameters for ``break``. +The **-h** or **--help** option displays help about using this command. Example ------- diff --git a/doc_src/cmds/continue.rst b/doc_src/cmds/continue.rst index 88d18284b..5b4f9e5b7 100644 --- a/doc_src/cmds/continue.rst +++ b/doc_src/cmds/continue.rst @@ -15,6 +15,8 @@ Description ``continue`` skips the remainder of the current iteration of the current inner loop, such as a :doc:`for ` loop or a :doc:`while ` loop. It is usually added inside of a conditional block such as an :doc:`if ` statement or a :doc:`switch ` statement. +The **-h** or **--help** option displays help about using this command. + Example ------- diff --git a/src/builtins/shared.rs b/src/builtins/shared.rs index 048b4c7b9..011afb4c3 100644 --- a/src/builtins/shared.rs +++ b/src/builtins/shared.rs @@ -978,6 +978,13 @@ fn builtin_break_continue( let is_break = argv[0] == "break"; let argc = argv.len(); + let opts = HelpOnlyCmdOpts::parse(argv, parser, streams)?; + + if opts.print_help { + builtin_print_help(parser, streams, argv[0]); + return Ok(SUCCESS); + } + 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); diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 657b1b658..1f2ca879a 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -442,6 +442,15 @@ eval continue #CHECKERR: Error-message: continue: Not inside of loop #CHECKERR: Documentation for continue +break -h +#CHECKERR: Documentation for break +break --help +#CHECKERR: Documentation for break +$dyn_break -h +#CHECKERR: Documentation for break +continue -h +#CHECKERR: Documentation for continue + # Test implicit cd. This should do nothing. ./