Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazy-loaded commands #13

Open
seeruk opened this issue Nov 13, 2018 · 0 comments
Open

Lazy-loaded commands #13

seeruk opened this issue Nov 13, 2018 · 0 comments

Comments

@seeruk
Copy link
Member

seeruk commented Nov 13, 2018

Extracted from work on an internal tool at Icelolly, this would be useful for larger applications with sprawling dependencies.

// We could make a function for adding factories for commands, to enable lazy-loading of commands,
// meaning their dependencies wouldn't be created if they weren't going to be used. Added like:
//
// app.AddCommandFactory("apply", resolver.ResolveApplyCommand)
//
// On the resolver, we'd have our factory function.
//
// func (r *Resolver) ResolveApplyCommand() *console.Command {
//     // ...
// }
//
// For sub-commands, we'd need to just do the same, but the factory functions would be passed as
// dependencies in the resolver. Something like:
//
// func (r *Resolver) ResolveContainerCommand() *console.Command {
//     return container.NewCommand(
//         r.ResolveContainerListCommand,
//         r.ResolveContainerInspectCommand,
//         // ...
//     )
// }
//
// Note that the factory function itself is passed in, the resolver is not being invoked at this
// point. This stops us from passing the resolver around, meaning that testing should still be easy
// enough to accomplish. We could just replace the sub-commands in tests with a no-op factory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant