Mirror of metasploit
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

opt_bool.rb 689B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # -*- coding: binary -*-
  2. module Msf
  3. ###
  4. #
  5. # Boolean option.
  6. #
  7. ###
  8. class OptBool < OptBase
  9. TrueRegex = /^(y|yes|t|1|true)$/i
  10. def type
  11. return 'bool'
  12. end
  13. def valid?(value, check_empty: true)
  14. return false if empty_required_value?(value)
  15. if ((value != nil and
  16. (value.to_s.empty? == false) and
  17. (value.to_s.match(/^(y|yes|n|no|t|f|0|1|true|false)$/i) == nil)))
  18. return false
  19. end
  20. true
  21. end
  22. def normalize(value)
  23. if(value.nil? or value.to_s.match(TrueRegex).nil?)
  24. false
  25. else
  26. true
  27. end
  28. end
  29. def is_true?(value)
  30. return normalize(value)
  31. end
  32. def is_false?(value)
  33. return !is_true?(value)
  34. end
  35. end
  36. end