Module: Umami::Options
- Included in:
- Runner
- Defined in:
- lib/chef-umami/options.rb
Instance Method Summary collapse
-
#parse_options ⇒ Object
Parse command line options.
Instance Method Details
#parse_options ⇒ Object
Parse command line options. Returns hash of options.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/chef-umami/options.rb', line 20 def = {} # Default options [:integration_tests] = true [:policyfile] = 'Policyfile.rb' [:test_root] = 'spec' [:unit_tests] = true parser = OptionParser.new do |opts| opts. = opts. + "\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: #{[:integration_tests]})") do |integration_tests| [:integration_tests] = integration_tests end opts.on('-p', '--policyfile POLICYFILE_PATH', 'Specify the path to a policy' \ " (DEFAULT: #{[:policyfile]})") do |policyfile| [: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| [:recipes] = recipes end opts.on('-t', '--test-root TEST_ROOT_PATH', "Specify the path into which we'll write tests" \ " (DEFAULT: #{[:test_root]})") do |test_root| [:test_root] = test_root end opts.on('-u', '--[no-]unit-tests', 'Write unit tests' \ " (DEFAULT: #{[:unit_tests]})") do |unit_tests| [: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.}" if e. =~ /--pattern/ puts 'Ah, this is likely parsed from `rspec` options. We can safely ignore this.' end puts 'Ignoring the option.' end end |