Para facilitar un procesamiento más complejo, echale un vistazo a
OptionParser, GetOptLong y gemas
como main o trollop, que te ayudan a procesar opciones pasadas como
argumentos. Por ejemplo,
este es un trozo de un script mío usando la gema main
require ‘main’
main {
description <<-DESC
Deletes or gzips jhub log files older than the specified dates,
searching the specified directories
recursively. The files should match this regexp
/^(\d\d\d\d-\d\d-\d\d).*.log(.gz)?$/
DESC
option(“zip”, “z”) {
argument :required
description “Zip files older than the specified number of days”
cast :int
}
option(“delete”, “d”) {
argument :required
defaults 7
description “Delete files older than the specified number of days.
If --zip option is specified, only delete the files that are in
between both dates”
cast :int
}
argument(“directories”) {
arity -2
}
def run
folders = params[:directories].values
have_to_zip = params[:zip].given?
zip = params[:zip].value
Resto del programa
…
}
Jesus.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.