Class: GeneratePuppetfile::OptParser
- Inherits:
-
Object
- Object
- GeneratePuppetfile::OptParser
- Defined in:
- lib/generate_puppetfile/optparser.rb
Overview
Internal: Parse the options provided to generate-puppetfile
Class Method Summary collapse
-
.parse(args) ⇒ Object
Internal: Initialize the OptionParser.
Class Method Details
.parse(args) ⇒ Object
Internal: Initialize the OptionParser
Returns an OptionParser object.
10 11 12 13 14 15 16 17 18 19 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 |
# File 'lib/generate_puppetfile/optparser.rb', line 10 def self.parse(args) = {} # Default values [:modulename] = 'profile' opts = OptionParser.new do |opts| opts. = 'generate-puppetfile [OPTIONS] [<MODULE> ... <MODULE>]' opts.on('-p', '--puppetfile FILE', 'Name of existing Puppetfile to verify and update') do |file| unless File.readable?(file) puts "\nPuppetfile '#{file}' cannot be read. Are you sure you passed in the correct filename?\n\n" exit 1 end [:puppetfile] = file end opts.on('-c', '--create_puppetfile', 'Create a Puppetfile in the working directory. Warning: overwrites any existing file with the same name.') do [:create_puppetfile] = true end opts.on('-f', '--create-fixtures', 'Create a .fixtures.yml file in the working directory. This works in a module directory or at the top of your controlrepo.') do [:create_fixtures] = true end opts.on('-m', '--modulename NAME', "Name of the module the fixtures file will be used with. Optional, for use with --create-fixtures when used in a module directory. Defaults to 'profile'.") do |name| [:modulename] = name end opts.on('-l', '--latest-versions', "Use latest version of forge modules and default branch of repository modules in .fixtures.yml") do |name| [:latest_versions] = true end opts.on('-s', '--silent', 'Run in silent mode. Supresses all non-debug output. Adds the -c flag automatically.') do [:silent] = true [:create_puppetfile] = true end opts.on('-d', '--debug', 'Enable debug logging') do [:debug] = true end opts.on_tail('-i', '--ignore-comments', 'Ignore comments') do [:ignore_comments] = true end opts.on_tail('--fixtures-only', 'Create a .fixtures.yml file from an existing Puppetfile. Requires the -p option.') do [:fixtures_only] = true end opts.on_tail('-v', '--version', 'Show version') do puts "generate-puppetfile v#{GeneratePuppetfile::VERSION}" exit end end opts.parse!(args) end |