summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandan Singh <csingh43@bloomberg.net>2018-06-06 19:21:14 +0100
committerTristan Van Berkom <tristan.van.berkom@gmail.com>2018-06-06 22:10:49 +0000
commit69e594433df417324f4015c0364088acfacc1a72 (patch)
treee1947b6a92e1fec9502b4122f2fdd2ff5a0f9120
parenta5ff465d9225ad894435f95ec03f6ee21968fcb1 (diff)
downloadbuildstream-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.
-rw-r--r--buildstream/_frontend/cli.py18
-rw-r--r--tests/completions/completions.py11
2 files changed, 24 insertions, 5 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:
diff --git a/tests/completions/completions.py b/tests/completions/completions.py
index cc98cb940..d6d0fde81 100644
--- a/tests/completions/completions.py
+++ b/tests/completions/completions.py
@@ -174,8 +174,9 @@ def test_option_directory(datafiles, cli, cmd, word_idx, expected, subdir):
['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], None),
# When running from the files subdir
- ('project', 'bst show ', 2, [], 'files'),
- ('project', 'bst build com', 2, [], 'files'),
+ ('project', 'bst show ', 2, [e + ' ' for e in PROJECT_ELEMENTS], 'files'),
+ ('project', 'bst build com', 2,
+ ['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], 'files'),
# When passing the project directory
('project', 'bst --directory ../ show ', 4, [e + ' ' for e in PROJECT_ELEMENTS], 'files'),
@@ -193,8 +194,10 @@ def test_option_directory(datafiles, cli, cmd, word_idx, expected, subdir):
['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], None),
# When running from the files subdir
- ('no-element-path', 'bst show ', 2, [], 'files'),
- ('no-element-path', 'bst build com', 2, [], 'files'),
+ ('no-element-path', 'bst show ', 2,
+ [e + ' ' for e in (PROJECT_ELEMENTS + ['project.conf'])] + ['files/'], 'files'),
+ ('no-element-path', 'bst build com', 2,
+ ['compose-all.bst ', 'compose-include-bin.bst ', 'compose-exclude-dev.bst '], 'files'),
# When passing the project directory
('no-element-path', 'bst --directory ../ show ', 4,