James Ennis pushed to branch jennis/add_artifacts_completion at BuildStream / buildstream
Commits:
2 changed files:
Changes:
... | ... | @@ -111,16 +111,7 @@ def complete_target(args, incomplete): |
111 | 111 |
return complete_list
|
112 | 112 |
|
113 | 113 |
|
114 |
-def complete_artifact(args, incomplete):
|
|
115 |
- from .._context import Context
|
|
116 |
- ctx = Context()
|
|
117 |
- |
|
118 |
- config = None
|
|
119 |
- for i, arg in enumerate(args):
|
|
120 |
- if arg in ('-c', '--config'):
|
|
121 |
- config = args[i + 1]
|
|
122 |
- ctx.load(config)
|
|
123 |
- |
|
114 |
+def complete_artifact(args, incomplete, ctx):
|
|
124 | 115 |
# element targets are valid artifact names
|
125 | 116 |
complete_list = complete_target(args, incomplete)
|
126 | 117 |
complete_list.extend(ref for ref in ctx.artifactcache.cas.list_refs() if ref.startswith(incomplete))
|
... | ... | @@ -135,6 +126,19 @@ def override_completions(cmd, cmd_param, args, incomplete): |
135 | 126 |
:param incomplete: the incomplete text to autocomplete
|
136 | 127 |
:return: all the possible user-specified completions for the param
|
137 | 128 |
"""
|
129 |
+ from .._context import Context
|
|
130 |
+ ctx = Context()
|
|
131 |
+ |
|
132 |
+ config = None
|
|
133 |
+ for i, arg in enumerate(args):
|
|
134 |
+ if arg in ('-c', '--config'):
|
|
135 |
+ try:
|
|
136 |
+ config = args[i + 1]
|
|
137 |
+ except IndexError:
|
|
138 |
+ # For example when trying to complete `bst --config `
|
|
139 |
+ # args[i + 1] does not exist.
|
|
140 |
+ pass
|
|
141 |
+ ctx.load(config)
|
|
138 | 142 |
|
139 | 143 |
if cmd.name == 'help':
|
140 | 144 |
return complete_commands(cmd, args, incomplete)
|
... | ... | @@ -150,7 +154,7 @@ def override_completions(cmd, cmd_param, args, incomplete): |
150 | 154 |
cmd_param.opts == ['--track-except']):
|
151 | 155 |
return complete_target(args, incomplete)
|
152 | 156 |
if cmd_param.name == 'artifacts':
|
153 |
- return complete_artifact(args, incomplete)
|
|
157 |
+ return complete_artifact(args, incomplete, ctx)
|
|
154 | 158 |
|
155 | 159 |
raise CompleteUnhandled()
|
156 | 160 |
|
1 | 1 |
import os
|
2 | 2 |
import pytest
|
3 |
-from tests.testutils import cli
|
|
3 |
+from tests.testutils import cli, cli_integration
|
|
4 | 4 |
|
5 | 5 |
# Project directory
|
6 | 6 |
DATA_DIR = os.path.dirname(os.path.realpath(__file__))
|
... | ... | @@ -281,3 +281,49 @@ def test_argument_element_invalid(datafiles, cli, project, cmd, word_idx, expect |
281 | 281 |
])
|
282 | 282 |
def test_help_commands(cli, cmd, word_idx, expected):
|
283 | 283 |
assert_completion(cli, cmd, word_idx, expected)
|
284 |
+ |
|
285 |
+ |
|
286 |
+@pytest.mark.datafiles(os.path.join(DATA_DIR, 'project'))
|
|
287 |
+def test_argument_artifact(cli, tmpdir, datafiles):
|
|
288 |
+ project = os.path.join(datafiles.dirname, datafiles.basename)
|
|
289 |
+ |
|
290 |
+ # Build an import element with no dependencies (as there will only be ONE cache key)
|
|
291 |
+ result = cli.run(project=project, args=['build', 'import-bin.bst']) # Has no dependencies
|
|
292 |
+ result.assert_success()
|
|
293 |
+ |
|
294 |
+ # Ensure this has it's own clean cache
|
|
295 |
+ cli.configure({
|
|
296 |
+ 'artifactdir': os.path.join(str(tmpdir), 'artifacts')
|
|
297 |
+ })
|
|
298 |
+ |
|
299 |
+ # Get the key and the artifact ref ($project/$element_name/$key)
|
|
300 |
+ key = cli.get_element_key(project, 'import-bin.bst')
|
|
301 |
+ artifact = os.path.join('test', 'import-bin', key)
|
|
302 |
+ |
|
303 |
+ # Test autocompletion of the artifact
|
|
304 |
+ cmds = [
|
|
305 |
+ 'bst artifact log ',
|
|
306 |
+ 'bst artifact log t',
|
|
307 |
+ 'bst artifact log test/'
|
|
308 |
+ ]
|
|
309 |
+ |
|
310 |
+ for i, cmd in enumerate(cmds):
|
|
311 |
+ word_idx = 3
|
|
312 |
+ result = cli.run(project=project, cwd=project, env={
|
|
313 |
+ '_BST_COMPLETION': 'complete',
|
|
314 |
+ 'COMP_WORDS': cmd,
|
|
315 |
+ 'COMP_CWORD': str(word_idx)
|
|
316 |
+ })
|
|
317 |
+ words = []
|
|
318 |
+ if result.output:
|
|
319 |
+ words = result.output.splitlines() # This leaves an extra space on each e.g. 'foo.bst ']
|
|
320 |
+ words = [word.strip() for word in words]
|
|
321 |
+ |
|
322 |
+ if i == 0:
|
|
323 |
+ expected = PROJECT_ELEMENTS + [artifact] # We should now be able to see the artifact
|
|
324 |
+ elif i == 1:
|
|
325 |
+ expected = ['target.bst', artifact]
|
|
326 |
+ elif i == 2:
|
|
327 |
+ expected = [artifact]
|
|
328 |
+ |
|
329 |
+ assert expected == words
|