How can I provide a command line interface to my Android app?

I would like to be able to type commands on my development machine (macOS/zsh) and have them do things on my Android app. This will require custom code in my Android app. What I’m trying to do is something similar to automating certain settings, so that I don’t have to navigate to the settings screen of my Android app manually. This is to help me save time while I’m developing my app.

How can I get started? I’d love to see some examples of this being done but have been having trouble finding them.

Are there any libraries that can help me with this?

Also, for bonus points, I’d love to be able to have some sort of autocomplete on my Mac command line. How might I build that?

Source: Android Questions