Move some functionality into Lib to make it available for cake shell