Tidy register-endpoint code.

Following on from a tip by Ghe, lets have less duplication in the
getopt loop.

Change-Id: Ibd96d9144a7dc327d0a5417279fecafe475eff2f