Ruby Trollop Examples & Reference

Last updated:
  • simplest usage

    opts = Trollop::options do
      opt :name, "product name", :type=>:string
      opt :template, "product template", :required => true, :type => :string
    end
    #access option value: opts[:option_name]
    
  • custom short forms

    opts = Trollop::options do
      opt :name, "product name", :type=>:string, :short=>:a
      opt :number, "product number", :type=>:int, :short=>:u
    end
    #if not specified, the first letter of the option name gets used as short form
    

Dialogue & Discussion