CLI Template
cli-template is a generator tool that builds a starter CLI project based on Thor. It is the successor tool to thor_template, which is also a tool that generates CLI projects. The main difference is cli-template uses colons for namespaced commands. The usage section demonstrates a namespaced command below.
The predecessor tool is covered in this original blog post, Build Thor CLI Project in Under a Second. It covers usage and also contains a video demo. An updated blog post will eventually be made, for now, refer to the original blog post.
Usage
cli-template new mycli
cd mycli
exe/mycli hello world
exe/mycli sub:goodbye world
The above generated a starter CLI project called mycli with a working hello command. The created project also has starter specs for you 😁
$ rake
Mycli::CLI
mycli
should hello world
should goodbye world
Finished in 1.12 seconds (files took 0.71706 seconds to load)
2 examples, 0 failures
Release
Once you are satisfied with the CLI tool, you can release it as a gem.
1. edit the mycli.gemspec
2. edit lib/mycli/version.rb
3. update the CHANGELOG.md
And run:
rake release
When installed as a gem, you no longer have to prepend exe in front of the command. For example, exe/mycli becomes the mycli command.
Auto Completion
The generated CLI tool supports TAB auto-completion. To enable auto, you can add this to your ~/.bashrc or ~/.profile:
eval $(mycli completions:script)
Remember to re-load your shell. Note, the auto completion will only work once you tool is installed and it's binary is avaialble in your PATH.
Installation
gem install cli-template
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am "Add some feature") - Push to the branch (
git push origin my-new-feature) - Create new Pull Request