Extract cli repository handling and support IVORY_REPOSITORY env

The bare minimum changes required. It's pretty hacky, but I _think_ something like this is better than nothing until we upgrade to Pirate.