twisted's twistd tool parsing command line parameters

1.5k Views Asked by At

I've got a simple .tac file with a simple service, I start it with:

twistd -y service.tac

and everything works fine. But inside the tac file I've got a hardcoded port for my service and I would like to make it dynamic. The most desired way I want to have it working is via standard unix command line arguments:

twistd -y service.tac --port 8081

and then I'd like to access the port variable somewhere inside the .tac file. Just like standard python modules: optparse and argparse. I was looking for such solution in Twisted, I found only https://twistedmatrix.com/documents/12.0.0/core/howto/options.html#auto6 which, I'm afraid, is not what I need, since I get this error:

$ twistd -y service.tac 
/usr/bin/twistd: option -y not recognized
/usr/bin/twistd: Try --help for usage details.

Does anyone know how to parametrize twistd tool?

1

There are 1 best solutions below

0
On BEST ANSWER

It looks as if the Twisted way of doing this is documented here:

https://twistedmatrix.com/documents/12.0.0/core/howto/tap.html

You write plugins that add 'subcommands' which can be used via the CLI