!Mac OS X-10.15.7!ruby-2.7.1p83
thor
If you try to have several behaviors in one command, you need to handle options properly. There are several CLI builder gems for that. You can check the popularity at http://52.198.30.45/categories/CLI+Builder. Here, we will introduce thor. This can be achieved with a DSL similar to Rakefile.
First of all
gem install thor
please.
further,
require 'thor'
require "hello_rudy/version"
class HelloRudyCLI < Thor
desc "hello NAME", "say hello to NAME"
def hello(name)
puts "Hello " + name
end
end
HelloRudyCLI.start(ARGV)
If you correct it, it will almost work. The CLI string must be at the end of the class name.
To make it work properly, modify the area below.
> in hello_rudy.gemspec
spec.add_runtime_dependency('thor')
> bundle update
> bundle install
> cat lib/hello_rudy/version.rb
class HelloRudy #
VERSION = "0.1.0"
end
It's done.
When I try to move it to local with bundle
> bundle exec exe/hello_rudy
Commands:
hello_rudy hello NAME # say hello to NAME
hello_rudy help [COMMAND] # Describe available commands or one specific command
> bundle exec exe/hello_rudy hello Rudy
Hello Rudy
It works like a CLI.
You can also use it from various places by doing rake install. Thor is also used in ruby on rails. I wonder if it was git too. .. .. There is a detailed explanation at https://github.com/erikhuda/thor/wiki. my \ _help and qiita \ _org use thor.
rubocop
Brief introduction
Have a look at the actual github issue. https://github.com/rubocop-hq/rubocop/issues/4644
Recommended Posts