discover command support, plugin support

Ok. Actually, all this code is too ugly and is a good candidate to be rewritten