diff options
author | Chandan Singh <csingh43@bloomberg.net> | 2018-06-06 19:21:14 +0100 |
---|---|---|
committer | Tristan Van Berkom <tristan.van.berkom@gmail.com> | 2018-06-06 22:10:49 +0000 |
commit | 69e594433df417324f4015c0364088acfacc1a72 (patch) | |
tree | e1947b6a92e1fec9502b4122f2fdd2ff5a0f9120 /buildstream | |
parent | a5ff465d9225ad894435f95ec03f6ee21968fcb1 (diff) | |
download | buildstream-69e594433df417324f4015c0364088acfacc1a72.tar.gz |
_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.
Diffstat (limited to 'buildstream')
-rw-r--r-- | buildstream/_frontend/cli.py | 18 |
1 files changed, 17 insertions, 1 deletions
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: |