diff options
author | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-11-19 17:26:59 +0000 |
---|---|---|
committer | Jonathan Maw <jonathan.maw@codethink.co.uk> | 2018-12-11 16:15:19 +0000 |
commit | a1dee91ec00cc51b21acc1274887225325ea7baa (patch) | |
tree | 372ed18724be120f11f7c5cdf71f7874f8477d86 /buildstream/_context.py | |
parent | 7cf8334380a3454842b4263112a54c5cca4765f5 (diff) | |
download | buildstream-a1dee91ec00cc51b21acc1274887225325ea7baa.tar.gz |
Make specifying elements optional in bst commands
Known issues:
* `bst shell` works, but `bst shell COMMANDS...` doesn't, because click
has no way of separating optional args from variable-length args.
* `bst checkout` and `bst source-checkout`'s usage strings mark LOCATION
as an optional argument. Because click gets confused if there's an
optional argument before a mandatory argument, I had to mark LOCATION
as optional internally.
* `bst workspace open` makes no sense with element being optional, so
I skipped it.
* `bst workspace close` will probably need to be revisited when multiple
projects can own one workspace.
* `bst workspace reset` will happily delete the directory you're
currently in, requiring you to `cd $PWD` to see the contents of your
directory.
I could exclude the top-level directory of the workspace being
deleted, but it is entirely valid to run workspace commands from deeper
in the workspace.
This is a part of #222
Diffstat (limited to 'buildstream/_context.py')
-rw-r--r-- | buildstream/_context.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/buildstream/_context.py b/buildstream/_context.py index 9a12b2b27..a3487a794 100644 --- a/buildstream/_context.py +++ b/buildstream/_context.py @@ -32,7 +32,7 @@ from ._message import Message, MessageType from ._profile import Topics, profile_start, profile_end from ._artifactcache import ArtifactCache from ._artifactcache.cascache import CASCache -from ._workspaces import Workspaces, WorkspaceProjectCache +from ._workspaces import Workspaces, WorkspaceProjectCache, WORKSPACE_PROJECT_FILE from .plugin import _plugin_lookup @@ -649,6 +649,20 @@ class Context(): self._cascache = CASCache(self.artifactdir) return self._cascache + # guess_element() + # + # Attempts to interpret which element the user intended to run commands on + # + # Returns: + # (str) The name of the element, or None if no element can be guessed + def guess_element(self): + workspace_project_dir, _ = utils._search_upward_for_files(self._directory, [WORKSPACE_PROJECT_FILE]) + if workspace_project_dir: + workspace_project = self._workspace_project_cache.get(workspace_project_dir) + return workspace_project.get_default_element() + else: + return None + # _node_get_option_str() # |