Sha256: 2a947841c953c6b6868c18081fbc4fdf029b118b3696d2436e8dff7ec521ec44

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

# play with optparse

# A script that will pretend to resize a number of images
require 'optparse'

# This hash will hold all of the options
# parsed from the command-line by
# OptionParser.
options = {}

optparse = OptionParser.new do |opts|

  # Define the options, and what they do
  options[:verbose] = false
  opts.on( '-v', '--verbose', 'Output more information' ) do
    options[:verbose] = true
  end

  options[:quick] = false
  opts.on( '-q', '--quick', 'Perform the task quickly' ) do
    options[:quick] = true
  end

  options[:logfile] = nil
  opts.on( '-l', '--logfile FILE', 'Write log to FILE' ) do |file|
    options[:logfile] = file
  end
end

puts ARGV.inspect

# Parse the command-line. Remember there are two forms
# of the parse method. The 'parse' method simply parses
# ARGV, while the 'parse!' method parses ARGV and removes
# any options found there, as well as any parameters for
# the options. What's left is the list of files to resize.
optparse.parse!

puts "Being verbose" if options[:verbose]
puts "Being quick" if options[:quick]
puts "Logging to file #{options[:logfile]}" if options[:logfile]

p ARGV

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nrser-rash-0.2.3 dev/scratch/optparse.rb
nrser-rash-0.2.2 dev/scratch/optparse.rb
nrser-rash-0.2.1 dev/scratch/optparse.rb
nrser-rash-0.2.0 dev/scratch/optparse.rb