summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-05 00:22:33 -0400
committerTristan Van Berkom <tristan.vanberkom@codethink.co.uk>2017-09-05 01:57:53 -0400
commit43d3c4acd0d987986ca13dd198d2058368ce2a76 (patch)
tree9223e6469a2039b45fface19f042e3bc212fa920
parentc34e612852a99f509437f80090d4aef973adfda6 (diff)
downloadbuildstream-43d3c4acd0d987986ca13dd198d2058368ce2a76.tar.gz
_frontend/complete.py: Return whether completions were handled instead of exiting
Leave that choice to the calling code. Also some additional cleanup. Removed some bits of code borrowed from click but unused in this context, just because it's futzing up the coverage reports.
-rw-r--r--buildstream/_frontend/complete.py40
1 files changed, 6 insertions, 34 deletions
diff --git a/buildstream/_frontend/complete.py b/buildstream/_frontend/complete.py
index fef6a624f..e00a66858 100644
--- a/buildstream/_frontend/complete.py
+++ b/buildstream/_frontend/complete.py
@@ -67,10 +67,7 @@ def complete_path(path_type, incomplete, base_directory='.'):
# If there was nothing on the left of the last separator,
# we are completing files in the filesystem root
- if not base_path:
- base_path = os.path.sep
- else:
- base_path = os.path.join(base_directory, base_path)
+ base_path = os.path.join(base_directory, base_path)
elif os.path.isdir(incomplete):
base_path = incomplete
@@ -133,14 +130,6 @@ def get_param_type_completion(param_type, incomplete):
return []
-def get_completion_script(prog_name, complete_var):
- return (COMPLETION_SCRIPT % {
- 'complete_func': '_bst_completion',
- 'script_names': 'bst',
- 'autocomplete_var': complete_var,
- }).strip() + ';'
-
-
def resolve_ctx(cli, prog_name, args):
"""
Parse into a hierarchy of contexts. Contexts are connected through the parent variable.
@@ -304,30 +293,13 @@ def do_complete(cli, prog_name, override):
click.echo(item)
-def bashcomplete(cli, prog_name, complete_instr, override):
- if complete_instr == 'source':
- click.echo(get_completion_script(prog_name, '_BST_COMPLETION'))
- return True
- elif complete_instr == 'complete':
- do_complete(cli, prog_name, override)
- return True
- return False
-
-
-def fast_exit(code):
- """Exit without garbage collection, this speeds up exit by about 10ms for
- things like bash completion.
- """
- sys.stdout.flush()
- sys.stderr.flush()
- os._exit(code)
-
-
# Main function called from main.py at startup here
#
def main_bashcomplete(cmd, prog_name, override):
"""Internal handler for the bash completion support."""
- complete_instr = os.environ.get('_BST_COMPLETION')
- if complete_instr and bashcomplete(cmd, prog_name, complete_instr, override):
- fast_exit(1)
+ if '_BST_COMPLETION' in os.environ:
+ do_complete(cmd, prog_name, override)
+ return True
+
+ return False