How to add CLI to your own Ruby Gem and publish it!

Thor is a toolkit for building powerful command-line interfaces.

Setup Thor

I’m going to use Thor on our gem created in a previous article here. But first, as you have might have guessed, we need to install Thor gem package in our system with gem install thor

PUBLISHING YOUR GEM

Now that we have created our gem, we are ready to share it! One could create gems for their own development workgroup and make it private or make it public so that everyone can use it. I believe the simplest way to distribute a gem for public use is to use RubyGems.org. As you probably already know, gems that are published to RubyGems.org can be installed by gem install command.

My first gem is published!
one small step for man, one giant leap for mankind

An Alternative Way

There is one more cool trick you might want to know about Bundler package manager, let’s say we didn’t publish our gem on RubyGems but we have a GitHub repository where our gem build is located at. ( Note that gemspec file must be present in this repository) We can do the following in our project’s gemfile.

Conclusion

There is not much to say about the process but it is due to the fact that it is quite simple to do! We had a brief overview of Thor’s functionalities and application after that I’ve shown how to publish Ruby gems via RubyGems.org. There are lots of information about handling and maintaining Ruby gems on RubyGems.org, for more detailed information I’d suggest you take a look at their documentation.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ali Erbay

Ali Erbay

7 Followers

Full Stack Developer BDD/TDD || Ruby on Rails || React || React Native || NodeJS || Express https://github.com/kermit-klein