We keep duplicating this function all over the place. Factor it out and modernize it. Test: all the test commands named in the readme Bug: None Change-Id: I8d90a9c101b9cf83d62d02141f40c6c3666bdf94