I have a program which perform different actions depending on the plugins that are passed. For example, python main.py -m foo -m bar
will perform the actions of foo
and bar
.
The structure of the directory is:
├── Dockerfile ├── README.md ├── docker-compose.yml ├── entrypoint.sh ├── modules │ └── foo.py │ └── bar.py ├── main.py ├── requirements.txt └── settings.yaml
And in main.py
, I have a function for each of the plugins. Assume the following:
def foo(): ... def bar(): ... if args.all or 'foo' in args.modules: foo() elif args.all or 'bar' in args.modules: bar()
This works but there must be certainly a better way to work with plugins , because as the number of module grows, having a function and an if
for each one doesn't look like a good option.
What's the recommended way to do an implementation like this one?