Refactor some API bits and improve the error displayed to the user when using 'opam repository <COMMAND>s'