If you're a zsh user there is a fun^wquirky way to achieve similar functionality using the MULTI_FUNC_DEF¹ option. zsh allows you to define multiple functions at the same time, so you can parametrize functions with something like:
FYI one can avoid duping a command to echo it out as in some of the examples by using set -x (set -o xtrace). It can be disabled with set +x afterwards, or you can run it and your desired command in a subshell if performance is not a priority.
Having two copies of cmdline in the function is not a good design and probably most easily avoided with metaprogramming by building the cmdline first and then using it to echo and run it.
I do suspect the examples are intentionally very simplified though.
echoeval(){
CMD="$@"
echo "$ $CMD"
eval "$CMD"
}
echoeval ssh test -A
Variants that take a first parameter for coloring output, directing to stdout/stderr, or (for one-shot commands) variant that colors output based on return value -- are functions I have written.
You can even use brace expansion in your function definition, iff you define it using the function keyword like "function {build,qa,test}_ssh()".
---
There might be a nice solution to this with fish too, as you could create per-machine symlinks in your ~/.config/fish/functions to add a new machine.
¹ https://zsh.sourceforge.io/Doc/Release/Options.html