[Notes] [Git][BuildStream/buildstream][jennis/add_artifacts_completion] 2 commits: _frontend: Do not ignore regular args in bash completion



Title: GitLab

Jürg Billeter pushed to branch jennis/add_artifacts_completion at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • buildstream/_frontend/cli.py
    ... ... @@ -161,7 +161,7 @@ def override_main(self, args=None, prog_name=None, complete_var=None,
    161 161
         # Hook for the Bash completion.  This only activates if the Bash
    
    162 162
         # completion is actually enabled, otherwise this is quite a fast
    
    163 163
         # noop.
    
    164
    -    if main_bashcomplete(self, prog_name, override_completions):
    
    164
    +    if main_bashcomplete(self, prog_name, args, override_completions):
    
    165 165
     
    
    166 166
             # If we're running tests we cant just go calling exit()
    
    167 167
             # from the main process.
    

  • buildstream/_frontend/complete.py
    ... ... @@ -313,10 +313,10 @@ def get_choices(cli, prog_name, args, incomplete, override):
    313 313
                 yield item
    
    314 314
     
    
    315 315
     
    
    316
    -def do_complete(cli, prog_name, override):
    
    316
    +def do_complete(cli, prog_name, args, override):
    
    317 317
         cwords = split_arg_string(os.environ['COMP_WORDS'])
    
    318 318
         cword = int(os.environ['COMP_CWORD'])
    
    319
    -    args = cwords[1:cword]
    
    319
    +    args = args + cwords[1:cword]
    
    320 320
         try:
    
    321 321
             incomplete = cwords[cword]
    
    322 322
         except IndexError:
    
    ... ... @@ -328,11 +328,11 @@ def do_complete(cli, prog_name, override):
    328 328
     
    
    329 329
     # Main function called from main.py at startup here
    
    330 330
     #
    
    331
    -def main_bashcomplete(cmd, prog_name, override):
    
    331
    +def main_bashcomplete(cmd, prog_name, args, override):
    
    332 332
         """Internal handler for the bash completion support."""
    
    333 333
     
    
    334 334
         if '_BST_COMPLETION' in os.environ:
    
    335
    -        do_complete(cmd, prog_name, override)
    
    335
    +        do_complete(cmd, prog_name, args, override)
    
    336 336
             return True
    
    337 337
     
    
    338 338
         return False

  • tests/completions/completions.py
    ... ... @@ -281,3 +281,44 @@ 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
    +    # Get the key and the artifact ref ($project/$element_name/$key)
    
    295
    +    key = cli.get_element_key(project, 'import-bin.bst')
    
    296
    +    artifact = os.path.join('test', 'import-bin', key)
    
    297
    +
    
    298
    +    # Test autocompletion of the artifact
    
    299
    +    cmds = [
    
    300
    +        'bst artifact log ',
    
    301
    +        'bst artifact log t',
    
    302
    +        'bst artifact log test/'
    
    303
    +    ]
    
    304
    +
    
    305
    +    for i, cmd in enumerate(cmds):
    
    306
    +        word_idx = 3
    
    307
    +        result = cli.run(project=project, cwd=project, env={
    
    308
    +            '_BST_COMPLETION': 'complete',
    
    309
    +            'COMP_WORDS': cmd,
    
    310
    +            'COMP_CWORD': str(word_idx)
    
    311
    +        })
    
    312
    +        words = []
    
    313
    +        if result.output:
    
    314
    +            words = result.output.splitlines()  # This leaves an extra space on each e.g. 'foo.bst ']
    
    315
    +            words = [word.strip() for word in words]
    
    316
    +
    
    317
    +            if i == 0:
    
    318
    +                expected = PROJECT_ELEMENTS + [artifact]  # We should now be able to see the artifact
    
    319
    +            elif i == 1:
    
    320
    +                expected = ['target.bst', artifact]
    
    321
    +            elif i == 2:
    
    322
    +                expected = [artifact]
    
    323
    +
    
    324
    +            assert expected == words



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]