Now we will learn about what an RBCli project looks like and how to start using it.
RBCli can initialize a tool in three different modes:
If you’ve been following along with the tutorial, you’ve already seen Project Mode. An RBCli Project consists of several folders, each of which has a specific function. The RBCli framework handles loading and parsing the code automatically. To generate a standard, full-featured RBCli project, run:
rbcli init -n mytool
where mytool
can be replaced with any other command name you’d like. (We will continue using mytool
in this tutorial though!)
Inside the newly created mytool
folder you will see a bunch of files and folders related to your project. We will go over the structure later.
If you need to write a CLI tool but project mode feels a bit overkill for you – if you think a single-file script is all that is needed – that’s where the Mini and Micro modes come in. Instead of generating a full directory tree, you get only a single file that contains most of the functionality of RBCli. To use it, run:
rbcli init -n mytool -t mini
# or
rbcli init -n mytool -t micro
The only difference between the two is that mini
will show you all available options and some documentation to help you, while micro
is for advanced users who just want the samllest file possible.
As far as documentation goes, every piece of code present in those files is identical to Project mode so it should be pretty easy to navigate.
An RBCli project has the following structure:
<name>/
|--- application/
| |--- commands/
| | |--- scripts/
| |--- options.rb
|--- config/
|--- exe/
| |--- <name>
|--- hooks/
|--- lib/
| |--- <name>/
| |--- <name>.rb
|--- spec/
|--- userconf/
|--- .gitignore
|--- .rbcli
|--- .rspec
|--- CODE_OF_CONDUCT.md
|--- Gemfile
|--- README.md
|--- Rakefile
|--- <name>.gemspec
A few files aren’t part of RBCli itself, but are provided for your convenience. If you’re experienced in Ruby and Git you can skip over this.
.gitignore
.rspec
Gemfile
Gemspec
README.md
CODE_OF_CONDUCT.md
Rakefile
There is a lot of controvesy online regarding using the gemfile
vs the gemspec
. If you are new to Ruby in general then I suggest declaring your dependencies in the gemspec and leaving the gemfile
as-is. This keeps things simple and allows publishing and distributing your tool as a gem.
Additionally, note that a git repo is not created automatically. Using git is out of scope of this tutorial, but you can find tutorials here.
application/
config/
exe/
hooks/
lib/
require 'abc.rb'
without worrying about where they are located on the filesystem.userconf/
spec/
.rbcli
For the purposes of getting started right now, you don’t actually need to edit any of the defaults already present.
We just finished going through what an RBCli project looks like. Now let’s create our first application with it!