AbGuthrie / goquery

Provide a shell like interface by utilizing osquery's distributed API
MIT License
80 stars 10 forks source link

Rearchitect the Command Code #63

Closed obelisk closed 5 years ago

obelisk commented 5 years ago

This fixes systemic problem with the architecture of the command code: DRY.

The code before had a suggestions map along with a command map. If a new command was added, you needed to remember to update both or the the command wouldn't work (but goquery would still run) or it wouldn't suggest (even though it was there).

This fixes that by creating a command structure that contains three function pointers: an execute, a help, and a generate command specific suggestions.

This means that all the code and info about a command is packaged together in one file and it's impossible not to write a help function for it guaranteeing that every new command will suggest correctly.

This also makes it trivial to package suggestion generation into the command in question, when the prompt recognizes a full command has been typed, it will call into the command structure for more specific suggestions. Not all commands have suggestions but some do and I've described some of them below:

connect/disconnect: Suggests currently connected hosts mode: Suggests printing modes resume: Suggests past queries on that host

Closes: #34