From 972528648c1cd365b7114787af9a38bf57debbab Mon Sep 17 00:00:00 2001 From: Nahor Date: Wed, 24 Jun 2026 09:52:53 -0700 Subject: [PATCH] contains: clarify options handling The documentation sounded like options where handled in a fairly standard way, meaning options and `--` could be anywhere in the command line. In reality, options have to be first, followed by `--`, then the key. Document that behavior more explicitly, and add a test to detect if this changes. --- doc_src/cmds/contains.rst | 13 +++++++++++-- tests/checks/basic.fish | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/doc_src/cmds/contains.rst b/doc_src/cmds/contains.rst index 556c00df3c55..7fbc0af995f0 100644 --- a/doc_src/cmds/contains.rst +++ b/doc_src/cmds/contains.rst @@ -6,7 +6,7 @@ Synopsis .. synopsis:: - contains [OPTIONS] KEY [VALUES ...] + contains [OPTIONS] [--] KEY [VALUES ...] Description ----------- @@ -22,7 +22,9 @@ The following options are available: **-h** or **--help** Displays help about using this command. -Note that ``contains`` interprets all arguments starting with a **-** as an option to ``contains``, until an **--** argument is reached. +Options must be passed before *KEY*. +All arguments after *KEY* will be considered a value, regardless if they start with a ``-`` or not, including ``--``. +If *KEY* itself starts with a ``-``, use a ``--`` argument to separate it from the options. See the examples below. @@ -62,3 +64,10 @@ While this will check if function ``hasargs`` is being ran with the **-q** optio The **--** here stops ``contains`` from treating **-q** to an option to itself. Instead it treats it as a normal string to check. + +:: + + contains -i foo -q -- foo + + +This returns 3, since all arguments after the key are considered a value. diff --git a/tests/checks/basic.fish b/tests/checks/basic.fish index 9a5c5064b4ee..28b29303d662 100644 --- a/tests/checks/basic.fish +++ b/tests/checks/basic.fish @@ -229,6 +229,8 @@ contains -i string a b c d; or echo nothing #CHECK: nothing contains -i -- string a b c string d #CHECK: 4 +contains -i a -q -- a b c +#CHECK: 3 contains -i -- -- a b c; or echo nothing #CHECK: nothing contains -i -- -- a b c -- v