From 69e594433df417324f4015c0364088acfacc1a72 Mon Sep 17 00:00:00 2001 From: Chandan Singh Date: Wed, 6 Jun 2018 19:21:14 +0100 Subject: _frontend/cli.py: Try to autocomplete element paths when running from a subdirectory The previous commit added support for running bst commands form subdirectories of the project root. Make autocomplete also work in a similar way. --- buildstream/_frontend/cli.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'buildstream/_frontend') diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 41e97cb0e..5ed967d9d 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -20,6 +20,18 @@ def complete_target(args, incomplete): :return: all the possible user-specified completions for the param """ + project_conf = 'project.conf' + + def ensure_project_dir(directory): + directory = os.path.abspath(directory) + while not os.path.isfile(os.path.join(directory, project_conf)): + parent_dir = os.path.dirname(directory) + if directory == parent_dir: + break + directory = parent_dir + + return directory + # First resolve the directory, in case there is an # active --directory/-C option # @@ -35,10 +47,14 @@ def complete_target(args, incomplete): if idx >= 0 and len(args) > idx + 1: base_directory = args[idx + 1] + else: + # Check if this directory or any of its parent directories + # contain a project config file + base_directory = ensure_project_dir(base_directory) # Now parse the project.conf just to find the element path, # this is unfortunately a bit heavy. - project_file = os.path.join(base_directory, 'project.conf') + project_file = os.path.join(base_directory, project_conf) try: project = _yaml.load(project_file) except LoadError: -- cgit v1.2.1