Build Thor CLI Project in Under a Second
Update 9/5/2018: The video is old and demos the older version of the tool called thor_template. The new tool is called cli-template. I’ve updated the blog post but not the video.
These two tools seem pretty cool too:
- http://piotrmurach.github.io/tty/: Thor based also.
- davetron5000.github.io/methadone/: Has it’s own CLI parser.
Thanks @eashman for showing me the tools.
In this post, we’ll build a CLI project that is based on Thor in under a second.
The cli-template tool builds a fully functional CLI command based on Thor. The commands immediately work and there are even specs.
Quick Start
Summary of commands so you can copy and paste:
gem install cli-template
cli-template new mycli
cd mycli
exe/mycli help
exe/mycli hello world
rake
A Little More Details
Commands with a little more detailed explaination. Install and generate the project:
gem install cli-template
cli-template new mycli
cd mycli
What the generated directory structure looks like:
$ tree
.
├── CHANGELOG.md
├── exe
│ └── mycli
├── Gemfile
├── Gemfile.lock
├── Guardfile
├── lib
│ ├── mycli
│ │ ├── cli.rb
│ │ ├── command.rb
│ │ ├── completer
│ │ │ ├── script.rb
│ │ │ └── script.sh
│ │ ├── completer.rb
│ │ ├── help
│ │ │ ├── completion.md
│ │ │ ├── completion_script.md
│ │ │ ├── hello.md
│ │ │ └── sub
│ │ │ └── goodbye.md
│ │ ├── help.rb
│ │ ├── sub.rb
│ │ └── version.rb
│ └── mycli.rb
├── LICENSE.txt
├── mycli.gemspec
├── Rakefile
├── README.md
└── spec
├── lib
│ └── cli_spec.rb
└── spec_helper.rb
8 directories, 24 files
Default help menu provided:
$ exe/mycli help
Commands:
mycli hello NAME # say hello to NAME
mycli help [COMMAND] # Describe available commands or one specific command
Options:
[--verbose], [--no-verbose]
[--noop], [--no-noop]
$
A built-in starter command provided:
$ exe/mycli hello tung
Hello tung
$
Spec output:
$ rake spec
Mycli::CLI
mycli
should hello world
Finished in 0.10423 seconds (files took 0.29091 seconds to load)
1 example, 0 failures
$
Hope you enjoyed this post 🎊
Thanks for reading this far. If you found this article useful, I'd really appreciate it if you share this article so others can find it too! Thanks 😁 Also follow me on Twitter.
Got questions? Check out BoltOps.
You might also like
More tools:
-
Kubes
Kubes: Kubernetes Deployment Tool
Kubes is a Kubernetes Deployment Tool. It builds the docker image, creates the Kubernetes YAML, and runs kubectl apply. It automates the deployment process and saves you precious finger-typing energy.
-
Jets
Jets: The Ruby Serverless Framework
Ruby on Jets allows you to create and deploy serverless services with ease, and to seamlessly glue AWS services together with the most beautiful dynamic language: Ruby. It includes everything you need to build an API and deploy it to AWS Lambda. Jets leverages the power of Ruby to make serverless joyful for everyone.
-
Lono
Lono: The CloudFormation Framework
Building infrastructure-as-code is challenging. Lono makes it much easier and fun. It includes everything you need to manage and deploy infrastructure-as-code.