Add tabcompletion support

Add proper tabcompletion support. Most work is code cleanup and adding unittests.
this requires some work in CCM and possibly a slightly different way to call the cachemanager from `ncm-query`. i'll see if i can make it part of this PR.