This is similar to the approach I take in my markup language: https://github.com/smasher164/mexdown. Pipe the body of a code block to the command's stdin, and replace the code block with its output.
I built something in a similar spirit to your comment and this larger thread, albeit a bit simplistic. Lets you document and write your bash scripts in a markdown file, then you can run the blocks. It figures out what arguments you expect in a block and turns them into CLI flags. https://github.com/khalidx/runbook
Not sure how useful it is but I use it to maintain a collection of documented bash scripts.