Writing shell completions is a surprisingly tricky - especially for larger CLI tools or when you want to provide more advanced suggestions. Everything has to be done imperatively, usually as a shell script! It can get hairy quickly.
As a point of comparison, see the difference between the git completions written in bash [1] vs the declarative equivalent [2].
[1] https://github.com/git/git/blob/master/contrib/completion/gi...
[2] https://github.com/withfig/autocomplete/blob/master/src/git....