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.
This commit is contained in:
Johannes Altmanninger
2025-09-17 14:49:24 +02:00
parent c77255aabc
commit 87c73b7fbf
4 changed files with 19 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ Description
``break`` halts a currently running loop (*LOOP_CONSTRUCT*), such as a :doc:`for <for>` or :doc:`while <while>` loop. It is usually added inside of a conditional block such as an :doc:`if <if>` block.
There are no parameters for ``break``.
The **-h** or **--help** option displays help about using this command.
Example
-------

View File

@@ -15,6 +15,8 @@ Description
``continue`` skips the remainder of the current iteration of the current inner loop, such as a :doc:`for <for>` loop or a :doc:`while <while>` loop. It is usually added inside of a conditional block such as an :doc:`if <if>` statement or a :doc:`switch <switch>` statement.
The **-h** or **--help** option displays help about using this command.
Example
-------

View File

@@ -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);

View File

@@ -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.
./