opscode/chef-dk — pull request #3 by danielsdeleo (2014-03-05 03:17:07+00:00)
Title: [wip] Rework the code loader to be as lazy as possible

This is quick-n-dirty, want to share it before I go any further.

The goal of this is to minimize the amount of work required to setup the CLI code so it can be as fast as possible. To achieve this, there is a DSL of sorts to setup the mapping between subcommand strings, the file where they're defined, and the class name of the subcommand. When the `chef` command runs, it reads the DSL to setup the mappings, but doesn't actually load any of the command code. Once the arguments are resolved to a particular command, that command's file is loaded and we use `const_get` to get a reference to the class. From there we can create an instance and run it.

This will be important once we start writing commands that have lots of gem dependencies because we either have to load all the dependencies when we hit the `require` statements, or else hide the `require` statements in a lazy loading block (knife does this, but there are some downsides to this approach that make the code a little unnatural). This will require a little extra work from plugin authors if we add a plugin feature to the cli, but I think the end-user benefits are worth it.