Skip to content

Commit

Permalink
completion_server: minor fixes
Browse files Browse the repository at this point in the history
* Options and arguments are now correctly listed for command aliases.
* Arguments are now correctly listed for `vip`.
* Some default options are now correctly listed for `gui` and `hub`.
  • Loading branch information
oliver-sanders committed Sep 20, 2023
1 parent 6157644 commit f5a27d9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 23 additions & 4 deletions cylc/flow/scripts/completion_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
list_resources as list_resources_,
RESOURCE_DIR,
)
from cylc.flow.scripts.cylc import COMMANDS
from cylc.flow.scripts.cylc import ALIASES, COMMANDS
from cylc.flow.scripts.scan import FLOW_STATES, get_pipe, ScanOptions
from cylc.flow.terminal import cli_function
from cylc.flow.workflow_files import infer_latest_run_from_id
Expand Down Expand Up @@ -181,7 +181,7 @@ async def complete_cylc(_root: str, *items: str) -> t.List[str]:
return await complete_command()
if length == 1:
return await complete_command(partial)
command: str = items[0]
command: str = ALIASES.get(items[0], items[0]) # resolve command aliases

# special logic for the pseudo "help" and "version" commands
if command == 'help':
Expand Down Expand Up @@ -314,6 +314,8 @@ def list_options(command: str) -> t.List[str]:
Note: This provides the long formats of options e.g. `--help` not `-h`.
"""
if command in COMMAND_OPTION_MAP:
return COMMAND_OPTION_MAP[command]

Check warning on line 318 in cylc/flow/scripts/completion_server.py

View check run for this annotation

Codecov / codecov/patch

cylc/flow/scripts/completion_server.py#L318

Added line #L318 was not covered by tests
try:
entry_point = COMMANDS[command].resolve()
except KeyError:
Expand Down Expand Up @@ -478,12 +480,29 @@ async def list_colours(
# non-exhaustive list of Cylc commands which take non-workflow arguments
COMMAND_MAP: t.Dict[str, t.Optional[t.Callable]] = {
# register commands which have special positional arguments
'install': list_src_workflows,
'get-resources': list_resources,
'install': list_src_workflows,
'vip': list_src_workflows,
# commands for which we should not attempt to complete arguments
'scan': None,
'cycle-point': None,
'hub': None,
'message': None,
'scan': None,
}


# commands we can't list options for in the standard way
COMMAND_OPTION_MAP = {
'gui': [
'--debug',
'--help',
'--new',
'--no-browser',
],
'hub': [
'--debug',
'--help',
],
}

# non-exhaustive list of Cylc CLI options
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/scripts/test_completion_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ async def test_complete_cylc(dummy_workflow):
'cylc', '62656566', '--77656C6C696E67746F6E='
) == set()

# $ cylc cat-log f<tab><tab>
assert await _complete_cylc('cylc', 'cat-log', 'f') == {'foo/run2//'}

# $ cylc log f<tab><tab> # NOTE: "log" is an alias for "cat-log"
assert await _complete_cylc('cylc', 'log', 'f') == {'foo/run2//'}

# $ cylc help <tab><tab>
assert 'all' in await _complete_cylc('cylc', 'help', '')

Expand Down

0 comments on commit f5a27d9

Please sign in to comment.