As a developer for Mocra and an open source guy, sometimes I publish gems under the dev@mocra account and other times at my own personal account. In order to do this however I need to edit the ~/.gem/credentials file every time I need to switch. Whilst it would be easy for me to make a script to just mv the file elsewhere and copy over the new one, I think there would also be other people in this situation.
Agreed, this is why ~/.gem/credentials
is a YAML file...so this could be implemented something like...
gem push whatever.gem -k mocra
and in the credentials file:
--- :rubygems_api_key: 1337 :mocra_api_key: 42
Makes me think of something related... we want to run a gemcutter instance to host our internal gems. Currently we have a company-specific gem which is exactly like the gemcutter one except it only provides the push command and point to our server. What if gemcutter supported something like:
gem push foo.gem -h foo
with h standing for host and defaulting to gemcutter. And the YAML file:
--- gemcutter: api_key: foo url: http://gemcutter.org foo: api_key: bar url: http://gems.example.org
I'd be happy to submit a patch if you are ok with this.
I like that approach better, sr...however we'll have to continue to support :rubygems_api_key
since the gemcutter gem looks at that too. So perhaps the default could be
--- rubygems: api_key: foo address: http://rubygems.org
Thankfully since it's parsed as a YAML file we should be able to drop this in.
This is done! https://github.com/rubygems/rubygems/pull/17
as this is the top search result for this problem and since I spent 20 minutes trying to figure out the right config format, I thought I'd clarify it here for others. Just specify each key as a symbol in ~/.gem/credentials
and specify which you want with -k
:work: b026324c6904b2a9cb4b88d6d61c81d1
:personal: b026324c6904b2a9cb4b88d6d61c81d1
gem push -k work mygem
Most helpful comment
as this is the top search result for this problem and since I spent 20 minutes trying to figure out the right config format, I thought I'd clarify it here for others. Just specify each key as a symbol in
~/.gem/credentials
and specify which you want with-k