Jaymon / captain

command line python scripts for humans
MIT License
13 stars 1 forks source link

Command.handle method wrapping #90

Closed Jaymon closed 2 weeks ago

Jaymon commented 2 months ago

I sometimes have need to do some initialization after Command.get_handle_params is called (so the command is in the correct state to execute with all the params set up) but before Command.handle is called. Basically, I want to do a context manager for some type of connection or something like that, and I can't just wrap Command.run because params won't be completely setup yet.

I first thought about just creating a handle_call method and having run call that method instead of handle but that seems like an extra method call for nothing.

Another approach would be to add a Command.handle_method_name property and then just have run use that (eg, getattr(self, self.handle_method_name)(*args, **kwargs))?