gem – trollop

trollop lets you easily create script parameters with meaningful names, instead of useing ARGV[0], ARGV[1],…etc.


I have released my new course on Udemy, Kubernetes By Example. Sign up now to get free lifetime access!

If you have the following in your ruby script:

cat ./testscript.rb
#!/usr/bin/env ruby

require 'trollop'

opts = Trollop::options do
  opt :hostname, "Server FQDN.", :type => :string

puts opts[:hostname]

Next we install the gem:

$ gem install trollop

Now we have builtin “help” feature:

$ ruby ./testscript.rb --help
  -h, --hostname=    Server FQDN.
  -e, --help            Show this message

Now if we do:

$ ruby ./testscript.rb