Add functioning -r option
Cherry picked "-r" from master.