Repository: kislyuk/argcomplete

Issue:
Skip completion for specific argument
I would like a specific argument (e.g. `--foo`) to not appear in the completion. Since the application is pretty modular I can't configure e.g. the global `CompletionFinder`. I found the option to set `help=argparse.SUPPRESS` but I still want a help text to be shown for `--help`.

I was thinking if something like this would be feasible:

```
arg = parser.add_argument('--foo', help='awesome option')
arg.completer = False
```

If anyone could be give me some pointers I am happy to provide a PR for this feature idea.

Comments:

Patch:
diff --git a/argcomplete/__init__.py b/argcomplete/__init__.py
index 25d4328..0c74918 100644
--- a/argcomplete/__init__.py
+++ b/argcomplete/__init__.py
@@ -6,7 +6,7 @@ from __future__ import absolute_import, division, print_function, unicode_litera
 import os, sys, argparse, contextlib
 from . import completers, my_shlex as shlex
 from .compat import USING_PYTHON2, str, sys_encoding, ensure_str, ensure_bytes
-from .completers import FilesCompleter
+from .completers import FilesCompleter, SuppressCompleter
 from .my_argparse import IntrospectiveArgumentParser, action_is_satisfied, action_is_open, action_is_greedy
 
 _DEBUG = "_ARC_DEBUG" in os.environ
@@ -346,8 +346,12 @@ class CompletionFinder(object):
 
         option_completions = []
         for action in parser._actions:
-            if action.help == argparse.SUPPRESS and not self.print_suppressed:
-                continue
+            if not self.print_suppressed:
+                completer = getattr(action, "completer", None)
+                if isinstance(completer, SuppressCompleter) and completer.suppress():
+                    continue
+                if action.help == argparse.SUPPRESS:
+                    continue
             if not self._action_allowed(action, parser):
                 continue
             if not isinstance(action, argparse._SubParsersAction):
diff --git a/argcomplete/completers.py b/argcomplete/completers.py
index 05a1b63..59d8b79 100644
--- a/argcomplete/completers.py
+++ b/argcomplete/completers.py
@@ -92,3 +92,17 @@ class _FilteredFilesCompleter(object):
 class DirectoriesCompleter(_FilteredFilesCompleter):
     def __init__(self):
         _FilteredFilesCompleter.__init__(self, predicate=os.path.isdir)
+
+class SuppressCompleter(object):
+    """
+    A completer used to suppress the completion of specific arguments
+    """
+
+    def __init__(self):
+        pass
+
+    def suppress(self):
+        """
+        Decide if the completion should be suppressed
+        """
+        return True


Test patch:
diff --git a/test/test.py b/test/test.py
index d552331..cbe2de3 100755
--- a/test/test.py
+++ b/test/test.py
@@ -19,7 +19,7 @@ from argcomplete import (
     ExclusiveCompletionFinder,
     _check_module
 )
-from argcomplete.completers import FilesCompleter, DirectoriesCompleter
+from argcomplete.completers import FilesCompleter, DirectoriesCompleter, SuppressCompleter
 from argcomplete.compat import USING_PYTHON2, str, sys_encoding, ensure_str, ensure_bytes
 
 IFS = "\013"
@@ -153,6 +153,30 @@ class TestArgcomplete(unittest.TestCase):
         for cmd, output in expected_outputs:
             self.assertEqual(set(self.run_completer(make_parser(), cmd, print_suppressed=True)), set(output))
 
+    def test_suppress_completer(self):
+        def make_parser():
+            parser = ArgumentParser()
+            parser.add_argument("--foo")
+            arg = parser.add_argument("--bar")
+            arg.completer = SuppressCompleter()
+            return parser
+
+        expected_outputs = (
+            ("prog ", ["--foo", "-h", "--help"]),
+            ("prog --b", [""])
+        )
+
+        for cmd, output in expected_outputs:
+            self.assertEqual(set(self.run_completer(make_parser(), cmd)), set(output))
+
+        expected_outputs = (
+            ("prog ", ["--foo", "--bar", "-h", "--help"]),
+            ("prog --b", ["--bar "])
+        )
+
+        for cmd, output in expected_outputs:
+            self.assertEqual(set(self.run_completer(make_parser(), cmd, print_suppressed=True)), set(output))
+
     def test_action_activation(self):
         def make_parser():
             parser = ArgumentParser()