summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-01-10 15:48:44 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2019-01-14 18:46:57 +0000
commit542cdaf047945e93de64b397629607b7cf6d4b53 (patch)
treed7335ab0d2c65aec166d572b8a1b5cd44e904010
parent10b3ee621df65884c4a76096a5242aa861f8f8ce (diff)
downloadbuildstream-542cdaf047945e93de64b397629607b7cf6d4b53.tar.gz
_frontend/cli.py: Also check original args for --config in bash completion
The path of the config file generated by testutils for completion tests is passed as regular argument, not via COMP_WORDS. Use that config file in complete_artifact() to ensure the test uses the right artifact directory.
-rw-r--r--buildstream/_frontend/cli.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py
index bdcf3ca27..b3e48d583 100644
--- a/buildstream/_frontend/cli.py
+++ b/buildstream/_frontend/cli.py
@@ -2,6 +2,7 @@ import os
import sys
from contextlib import ExitStack
from fnmatch import fnmatch
+from functools import partial
from tempfile import TemporaryDirectory
import click
@@ -111,14 +112,25 @@ def complete_target(args, incomplete):
return complete_list
-def complete_artifact(args, incomplete):
+def complete_artifact(orig_args, args, incomplete):
from .._context import Context
ctx = Context()
config = None
- for i, arg in enumerate(args):
- if arg in ('-c', '--config'):
- config = args[i + 1]
+ if orig_args:
+ for i, arg in enumerate(orig_args):
+ if arg in ('-c', '--config'):
+ try:
+ config = orig_args[i + 1]
+ except IndexError:
+ pass
+ if args:
+ for i, arg in enumerate(args):
+ if arg in ('-c', '--config'):
+ try:
+ config = args[i + 1]
+ except IndexError:
+ pass
ctx.load(config)
# element targets are valid artifact names
@@ -128,8 +140,9 @@ def complete_artifact(args, incomplete):
return complete_list
-def override_completions(cmd, cmd_param, args, incomplete):
+def override_completions(orig_args, cmd, cmd_param, args, incomplete):
"""
+ :param orig_args: original, non-completion args
:param cmd_param: command definition
:param args: full list of args typed before the incomplete arg
:param incomplete: the incomplete text to autocomplete
@@ -150,7 +163,7 @@ def override_completions(cmd, cmd_param, args, incomplete):
cmd_param.opts == ['--track-except']):
return complete_target(args, incomplete)
if cmd_param.name == 'artifacts':
- return complete_artifact(args, incomplete)
+ return complete_artifact(orig_args, args, incomplete)
raise CompleteUnhandled()
@@ -161,7 +174,7 @@ def override_main(self, args=None, prog_name=None, complete_var=None,
# Hook for the Bash completion. This only activates if the Bash
# completion is actually enabled, otherwise this is quite a fast
# noop.
- if main_bashcomplete(self, prog_name, override_completions):
+ if main_bashcomplete(self, prog_name, partial(override_completions, args)):
# If we're running tests we cant just go calling exit()
# from the main process.