Reduce code duplication in argument parsing (based on ros-infrastructure/ros_buildfarm#11)

This pull request is based on the previous one: ros-infrastructure/ros_buildfarm#11