Lab42, Programmers' Best Friend In Ruby 2
Options
Lets us specify command line options with the same syntax as ruby parameters
my_shiny_gem "hello" "world" :verbose answer: 42
Will yield
require 'lab42/options'
= Lab42::Options.new.parse ARGV
.args # --> %W{ hello world }
.first # --> "hello"
[:verbose] # --> true
.verbose # --> true
[:answer] # --> "42"
.answer # --> "42"
Multiple values
When providing the same key many times the options object will become an array
my_even_shiner_gem 42 tag: cool :mixed tag: hot mixed: pickels
Will yield
.args # --> %W{42}
[:tag] # --> %W{cool hot}
.mixed # --> [true, "pickels"]
Required and Default Arguments
Lab42::Options.new greeting: "hello", target: :required
will parse as follows:
greet target: "world" # target = "world", greeting = "hello"
greet target: "world" greeting: "cheerio" # target = "world", greeting = "cheerio"
greet greeting: "howdy" # error missing required argument :target"
Missing Features
Help Message Generation
Typed Arguments