This is mostly just trying to get some structure in place. I suspect that the implementation of the `query` command in this PR will get entirely replaced through improvements.