module Umami::Options
Public Instance Methods
parse_options()
click to toggle source
Parse command line options. Returns hash of options.
# File lib/chef-umami/options.rb, line 20 def parse_options options = {} # Default options options[:integration_tests] = true options[:policyfile] = 'Policyfile.rb' options[:test_root] = 'spec' options[:unit_tests] = true parser = OptionParser.new do |opts| opts.banner = opts.banner + "\n\nA taste you won't forget!\n\n" opts.on('-h', '--help', 'Prints this help message') { puts opts exit } opts.on('-i', '--[no-]integration-tests', 'Write integration tests' \ " (DEFAULT: #{options[:integration_tests]})") do |integration_tests| options[:integration_tests] = integration_tests end opts.on('-p', '--policyfile POLICYFILE_PATH', 'Specify the path to a policy' \ " (DEFAULT: #{options[:policyfile]})") do |policyfile| options[:policyfile] = policyfile end opts.on('-r', '--recipes RECIPE1,RECIPE2', Array, "Specify one or more recipes for which we'll write tests" \ ' (DEFAULT: All recipes)') do |recipes| options[:recipes] = recipes end opts.on('-t', '--test-root TEST_ROOT_PATH', "Specify the path into which we'll write tests" \ " (DEFAULT: #{options[:test_root]})") do |test_root| options[:test_root] = test_root end opts.on('-u', '--[no-]unit-tests', 'Write unit tests' \ " (DEFAULT: #{options[:unit_tests]})") do |unit_tests| options[:unit_tests] = unit_tests end opts.on('-v', '--version', 'Show version and exit') { puts "chef-umami v#{Umami::VERSION}" exit } end begin parser.parse! rescue OptionParser::InvalidOption => e puts "Warning: #{e.message}" if e.message =~ /--pattern/ puts 'Ah, this is likely parsed from `rspec` options. We can safely ignore this.' end puts 'Ignoring the option.' end options end