Skip to content

Commit c93558d

Browse files
committed
Added autocompletion for EC files
1 parent b395a81 commit c93558d

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

easybuild/cli/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@
1616
click, original_click
1717
])
1818

19-
from .options import EasyBuildCliOption
19+
from .options import EasyBuildCliOption, EasyconfigParam
2020

2121
from easybuild.main import main_with_hooks
2222

2323

2424
@click.command()
2525
@EasyBuildCliOption.apply_options
2626
@click.pass_context
27-
@click.argument('other_args', nargs=-1, type=click.UNPROCESSED, required=False)
27+
@click.argument('other_args', nargs=-1, type=EasyconfigParam(), required=False)
2828
def eb(ctx, other_args):
2929
"""EasyBuild command line interface."""
3030
args = []
3131
for key, value in getattr(ctx, 'hidden_params', {}).items():
3232
key = key.replace('_', '-')
33+
opt = EasyBuildCliOption.OPTIONS_MAP[key]
34+
if value in ['False', 'True']:
35+
value = value == 'True'
3336
if isinstance(value, bool):
3437
if value:
3538
args.append(f"--{key}")
3639
else:
37-
opt = EasyBuildCliOption.OPTIONS_MAP[key]
3840
if value and value != opt.default:
3941
if isinstance(value, (list, tuple)) and value:
4042
if isinstance(value[0], list):

easybuild/cli/options/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
from dataclasses import dataclass
66

77
from click.shell_completion import CompletionItem
8-
from easybuild.tools.options import EasyBuildOptions
8+
from easybuild.tools.options import EasyBuildOptions, set_up_configuration
9+
from easybuild.tools.robot import search_easyconfigs
10+
911

1012
opt_group = {}
1113
try:
@@ -89,6 +91,17 @@ def shell_complete(self, ctx, param, incomplete):
8991
return super().shell_complete(ctx, param, last)
9092

9193

94+
class EasyconfigParam(click.ParamType):
95+
"""Custom Click parameter type for easyconfig parameters."""
96+
name = 'easyconfig'
97+
98+
def shell_complete(self, ctx, param, incomplete):
99+
if not incomplete:
100+
return []
101+
set_up_configuration(args=["--ignore-index"], silent=True, reconfigure=True)
102+
return [CompletionItem(ec) for ec in search_easyconfigs(fr'^{incomplete}.*\.eb$', filename_only=True)]
103+
104+
92105
@dataclass
93106
class OptionData:
94107
name: str

0 commit comments

Comments
 (0)