Sha256: 05724c4a105fba041b0e17b9d4d8eb4f00a0a0e1e2c5a7169e8abcbf5cd8cbbf

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'optiflag'

# Example 3:  Adding validation rules to the value of an input flag
##  See the flags : "mode", "run_date", and "connection"
module Example extend OptiFlag::Flagset
  flag "dir" 
  flag "connection" do
    value_matches ["Connection string must be of the form username/password@servicename", /^\b.+\b\/\b.+@.+$/ ]
  end
  optional_flag "mode" do
    value_in_set ["read","write","execute"]
  end
  optional_flag "run_date" do
    value_matches ["run_date must be of the form mm/DD/YY",/^[0-9]{2}\/[0-9]{2}\/[0-9]{2,4}$/]
  end
  usage_flag "h","help","?"

  handle_errors_and_help 
end 

flag = ARGV.flag_value

puts "Mode flag is #{ flag.mode }" if flag.mode?
puts "Run Date flag is #{ flag.run_date }" if flag.run_date?
puts "Connection flag is #{ flag.connection }" if flag.connection?


# Try the following inputs
#h# ruby example_3.rb -dir directory -connection deklund/password@HAL.FBI.GOV -mode read -run_date 12/23/2005
## Breaks (breaks a validation rule)
#h# ruby example_3.rb -dir directory -connection 78GCTHR.com
#h# ruby example_3.rb -dir directory -connection deklund/password@HAL.FBI.GOV -mode CRACK! -run_date 12/23/2005

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
optiflag-0.6 doc/example/example_3.rb