diff options
author | Jürg Billeter <j@bitron.ch> | 2019-07-09 17:03:13 +0200 |
---|---|---|
committer | Jürg Billeter <j@bitron.ch> | 2019-07-16 15:36:10 +0200 |
commit | 20ba24b5c4233f02c9a9c973edf584589f920fc1 (patch) | |
tree | 8818ed37a9abdaa2357d4e18ba85957d0db93523 | |
parent | 3bd487e06e340efabe45ab54646e03b9610ae584 (diff) | |
download | buildstream-20ba24b5c4233f02c9a9c973edf584589f920fc1.tar.gz |
cli.py: Use Context as context manager
-rw-r--r-- | src/buildstream/_frontend/cli.py | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/buildstream/_frontend/cli.py b/src/buildstream/_frontend/cli.py index 8fd834825..d4686e4fc 100644 --- a/src/buildstream/_frontend/cli.py +++ b/src/buildstream/_frontend/cli.py @@ -117,30 +117,30 @@ def complete_target(args, incomplete): def complete_artifact(orig_args, args, incomplete): from .._context import Context - ctx = Context() - - config = None - if orig_args: - for i, arg in enumerate(orig_args): - if arg in ('-c', '--config'): - try: - config = orig_args[i + 1] - except IndexError: - pass - if args: - for i, arg in enumerate(args): - if arg in ('-c', '--config'): - try: - config = args[i + 1] - except IndexError: - pass - ctx.load(config) - - # element targets are valid artifact names - complete_list = complete_target(args, incomplete) - complete_list.extend(ref for ref in ctx.artifactcache.list_artifacts() if ref.startswith(incomplete)) + with Context() as ctx: - return complete_list + config = None + if orig_args: + for i, arg in enumerate(orig_args): + if arg in ('-c', '--config'): + try: + config = orig_args[i + 1] + except IndexError: + pass + if args: + for i, arg in enumerate(args): + if arg in ('-c', '--config'): + try: + config = args[i + 1] + except IndexError: + pass + ctx.load(config) + + # element targets are valid artifact names + complete_list = complete_target(args, incomplete) + complete_list.extend(ref for ref in ctx.artifactcache.list_artifacts() if ref.startswith(incomplete)) + + return complete_list def override_completions(orig_args, cmd, cmd_param, args, incomplete): |