Refactor out common context to make polymorphic commandline class building easier