Repository: pallets/click

Issue:
Bash completion understands options even after "--"
Click Bash Completion prints out `command`'s options for any string starting with a single dash even after the double dash separator.

I'm facing this problem because I'm trying to create a wrapper with Click and I would like to use Click's auto completion to print out options from my wrapped program.

So, supposing that I'm wrapping `git` and my program is called `logbuch`, my command line would be something like:
```sh
logbuch -g -- commit -<TAB>
```

Supposing I'm doing some workaround in-code to get the `git commit`'s options, I'm returning that as a list of strings from a callback to my `command` `argument` `autocompletion` param. Like this:
```sh
@click.argument('arg',nargs=-1,type=click.STRING,autocompletion=auto_comp_callback)
```

Is there any way to prevent Click from completing my `program`'s options instead of calling my `callback`? I have read this [code](https://github.com/pallets/click/blob/master/click/_bashcomplete.py#L246) and it sounds like that Click does not check for double dashes before calling the `start_of_option` at line 246.

Besides that, I think that this issue goes in opposite way to this statement at [Click docs](https://click.palletsprojects.com/en/7.x/arguments/#option-like-arguments): " After the `--` marker, all further parameters are accepted as arguments."

I'm using `python3.7` with Click installed by `python3.7 -m pip install click`.


Discussion:
I have commited a fix for this issue on my [Click fork](https://github.com/bertolinocastro/click/commit/55fcf198118d683163dc07265ba0cdfde5c57ff7).

I'm not doing a pull request since I'm not envolved with Click's development and you guys will certainly do a better fix.
Please make a PR here. Plenty of community members make PRs, otherwise nothing would ever get fixed.
I just did that. Please, tell me if I need to do anything else.

Resolving patch:
diff --git a/click/_bashcomplete.py b/click/_bashcomplete.py
--- a/click/_bashcomplete.py
+++ b/click/_bashcomplete.py
@@ -237,6 +237,8 @@ def get_choices(cli, prog_name, args, incomplete):
     if ctx is None:
         return []
 
+    has_double_dash = "--" in all_args
+
     # In newer versions of bash long opts with '='s are partitioned, but it's easier to parse
     # without the '='
     if start_of_option(incomplete) and WORDBREAK in incomplete:
@@ -247,7 +249,7 @@ def get_choices(cli, prog_name, args, incomplete):
         incomplete = ''
 
     completions = []
-    if start_of_option(incomplete):
+    if not has_double_dash and start_of_option(incomplete):
         # completions for partial options
         for param in ctx.command.params:
             if isinstance(param, Option) and not param.hidden:


Test patch:
diff --git a/tests/test_bashcomplete.py b/tests/test_bashcomplete.py
--- a/tests/test_bashcomplete.py
+++ b/tests/test_bashcomplete.py
@@ -1,5 +1,7 @@
 # -*- coding: utf-8 -*-
 
+import pytest
+
 import click
 from click._bashcomplete import get_choices
 
@@ -407,3 +409,28 @@ def hsub():
     # If the user exactly types out the hidden command, complete its subcommands.
     assert choices_without_help(cli, ['hgroup'], '') == ['hgroupsub']
     assert choices_without_help(cli, ['hsub'], '--h') == ['--hname']
+
+
+@pytest.mark.parametrize(
+    ("args", "part", "expect"),
+    [
+        ([], "-", ["--opt"]),
+        (["value"], "--", ["--opt"]),
+        ([], "-o", []),
+        (["--opt"], "-o", []),
+        (["--"], "", ["name", "-o", "--opt", "--"]),
+        (["--"], "--o", ["--opt"]),
+    ],
+)
+def test_args_with_double_dash_complete(args, part, expect):
+    def _complete(ctx, args, incomplete):
+        values = ["name", "-o", "--opt", "--"]
+        return [x for x in values if x.startswith(incomplete)]
+
+    @click.command()
+    @click.option("--opt")
+    @click.argument("args", nargs=-1, autocompletion=_complete)
+    def cli(opt, args):
+        pass
+
+    assert choices_without_help(cli, args, part) == expect