I am attempting to write a completion plugin for YunoHost. I am struggling with the following case, where an argument, optional or not, can take multiple values:
ynh app addaccess apps [apps ...] [-u [USERS [USERS ...]]]
Typical usage:
ynh app addaccess foo-app1 bar-app2 -u barfoo1 foobar2
I've managed to get suggestions for those two parameters apps
and USERS
with the following code but I can't have a behavior coherent with what the command can handle.
(_ynh_app_list
and _ynh_users_list
are calls to compadd
)
_yunohost_app_addaccess() {
_arguments -s -C \
'1:apps:_ynh_app_list' \
'*'{-u,--users}'[users]:users:_ynh_users_list'
}
The code above kinda works, except:
- after entering a single app name, it switches to the users.
-u
takes a single user (multiple-u
instances are valid though)
I tried *:apps:_ynh_app_list
, but ynh app addaccess foo-app1 -u user1 <TAB>
calls _ynh_app_list
instead of _ynh_users_list
What I would like to get is:
ynh app addaccess <TAB>
shows the completions provided by__ynh_app_list
ynh app addaccess foo-app1 <TAB>
still shows the completions provided by__ynh_app_list
- As soon as
-u
is entered, and whatever the number of words after-u
, all completion suggestions should come from__ynh_users_list
:yunohost app addaccess foo-app1 bar-app2 -u barfoo1 foobar2 <TAB>
still completes with a username form__ynh_users_list
Is it possible to achieve this, at least the last item ([-u USER [USER...]]
)? Thanks a lot! :)