Blossom Logo Deploy your apps with Blossom — Get Started
BoltOps Logo
Build Thor CLI Project in Under a Second header image

Build Thor CLI Project in Under a Second

Tung Nguyen Tung Nguyen · September 14, 2017
2 min read

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:

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 🎊

Blossom Logo
Deploy Your Apps with Ease

Blossom helps you and your AI agent deploy apps and keep them running. Start on managed Blossom Cloud or connect your own cloud account.

BoltOps Blog
Join a group of good-looking folks who get free email updates from BoltOps.