OpenCyphal / pycyphal

Python implementation of the Cyphal protocol stack.
https://pycyphal.readthedocs.io/
MIT License
119 stars 106 forks source link

CLI: configure transport via environment variable #117

Closed pavel-kirienko closed 3 years ago

pavel-kirienko commented 4 years ago

@aentinger says:

  1. As a user using the pyuavcan publish feature I’m interested first and foremost in publishing UAVCAN data on various transport layers. That’s why my focus is on setting up the message and not configuring the transportlayer which additionally is appended at the end of a already very long bash entry (alternatively it’s in front but the manipulation of the message is at the end, also undesirable). [...]

  2. As a typical user I’m not going to change my transport layer 3 times a day. Probably I’ll change it never. Therefore it might be worth considering to introduce “state” to the pyuavcan CLI tool which allows to permanently configure the desired transport layer. (pyuavcan config --gobal transport=CAN). It’s probably only you as the UAVCAN devs that need to change between various transport layers on a regular basis.

The action item would be to read the transport configuration from the environment variable PYUAVCAN_CLI_TRANSPORT unless at least one --transport/--tr is specified in the command line arguments. The contents of the variable is to replace the argument to --transport=. For redundant transports, the variable should evaluate to sequence.

For example, instead of:

uvc sub uavcan.diagnostic.Record.1.0 --tr="UDP('127.0.0.111/8')" --tr="Serial('socket://loopback:50905',111)"

You would say:

export PYUAVCAN_CLI_TRANSPORT="[UDP('127.0.0.111/8'), Serial('socket://loopback:50905',111)]"
uvc sub uavcan.diagnostic.Record.1.0

The first line then can be placed into the shell environment configuration script like ~/.bashrc to implement most commonly used configurations.