dynamic completion #181
-
Hi I'm playing with the bash completion part of bashly, and try to add some dynamic behavior I'm trying to add a command whose parameter is dynamically retrieve through a REST api request my completion is defined as follow :
but the validation fails at column 169 (colon after Accept) if I remove this part and it manually in the generated completion script, everything work fine thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Interesting. Well, this seems like a gross abuse of the completions mechanism, but I believe it should be still possible. That said, the error you are getting is not from bashly itself, but from the YAML parser. name: delete
help: Delete an object instance
commands:
- name: processor
help: delete a processor instance
completions: # this is the secret
- |
$(TOKEN=$(cat /tmp/access_token.txt) && eval $(cat /etc/env/environment.txt | grep API_URL) && curl -sL --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer ${TOKEN}" ${API_URL}/processors/ | jq .[].name) But still - this would not work. I would consider this approach instead:
- name: processor
help: delete a processor instance
completions:
- $(mycli get-completions) Now, you can test your completion command in isolation, and if it returns a compatible completions string (whitespace dlimted string), then there is no reason it wont work in the completions itself. Full working example:# bashly.yml
name: cli
commands:
- name: test
help: Test the completions
completions:
- $(./cli get-completions)
- name: get-completions
help: Return some completions
private: true # src/get_completions_command.sh
echo "one two three" Then you run: $ bashly g
$ bashly add comp script
$ source completions.bash
# test completions
$ ./cli get-completions
one two three
$ ./cli test <tab>
# and you get one two three here as well |
Beta Was this translation helpful? Give feedback.
Interesting.
Well, this seems like a gross abuse of the completions mechanism, but I believe it should be still possible.
It is hard for me to help you debug this problem since I have no access to your completions "server".
That said, the error you are getting is not from bashly itself, but from the YAML parser.
The below syntax should make it pass validation (the only thing you care about is the pipe in the completions string):