Class: Beaker::Options::CommandLineParser
- Inherits:
-
Object
- Object
- Beaker::Options::CommandLineParser
- Defined in:
- lib/beaker/options/command_line_parser.rb
Overview
An object that parses arguments in the format [‘–option’, ‘value’, ‘–option2’, ‘value2’, ‘–switch’]
Instance Method Summary collapse
-
#initialize ⇒ CommandLineParser
constructor
A new instance of CommandLineParser.
-
#parse!(args = ARGV) ⇒ Hash
Parse an array of arguments into a Hash of options.
-
#usage ⇒ String
Generate a string representing the supported arguments.
Constructor Details
#initialize ⇒ CommandLineParser
Note:
All of Beaker’s supported command line options are defined here
Returns a new instance of CommandLineParser.
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/beaker/options/command_line_parser.rb', line 10 def initialize @cmd_options = Beaker::Options::OptionsHash.new @optparse = OptionParser.new do|opts| # Set a banner opts. = "Usage: #{File.basename($0)} [options...]" opts.on '-h', '--hosts FILE', 'Use host configuration FILE', '(default sample.cfg)' do |file| @cmd_options[:hosts_file] = file end opts.on '-o', '--options-file FILE', 'Read options from FILE', 'This should evaluate to a ruby hash.', 'CLI optons are given precedence.' do |file| @cmd_options[:options_file] = file end opts.on '--type TYPE', 'one of git or pe', 'used to determine underlying path structure of puppet install', '(default pe)' do |type| @cmd_options[:type] = type end opts.on '--helper PATH/TO/SCRIPT', 'Ruby file evaluated prior to tests', '(a la spec_helper)' do |script| @cmd_options[:helper] = script end opts.on '--load-path /PATH/TO/DIR,/ADDITIONAL/DIR/PATHS', 'Add paths to LOAD_PATH' do |value| @cmd_options[:load_path] = value end opts.on '-t', '--tests /PATH/TO/DIR,/ADDITIONA/DIR/PATHS,/PATH/TO/FILE.rb', 'Execute tests from paths and files' do |value| @cmd_options[:tests] = value end opts.on '--pre-suite /PRE-SUITE/DIR/PATH,/ADDITIONAL/DIR/PATHS,/PATH/TO/FILE.rb', 'Path to project specific steps to be run BEFORE testing' do |value| @cmd_options[:pre_suite] = value end opts.on '--post-suite /POST-SUITE/DIR/PATH,/OPTIONAL/ADDITONAL/DIR/PATHS,/PATH/TO/FILE.rb', 'Path to project specific steps to be run AFTER testing' do |value| @cmd_options[:post_suite] = value end opts.on '--[no-]provision', 'Do not provision vm images before testing', '(default: true)' do |bool| @cmd_options[:provision] = bool end opts.on '--[no-]preserve-hosts', 'Preserve cloud instances' do |value| @cmd_options[:preserve_hosts] = value end opts.on '--root-keys', 'Install puppetlabs pubkeys for superuser', '(default: false)' do |bool| @cmd_options[:root_keys] = bool end opts.on '--keyfile /PATH/TO/SSH/KEY', 'Specify alternate SSH key', '(default: ~/.ssh/id_rsa)' do |key| @cmd_options[:keyfile] = key end opts.on '--timeout TIMEOUT', '(vCloud only) Specify a provisioning timeout (in seconds)', '(default: 300)' do |value| @cmd_options[:timeout] = value end opts.on '-i URI', '--install URI', 'Install a project repo/app on the SUTs', 'Provide full git URI or use short form KEYWORD/name', 'supported keywords: PUPPET, FACTER, HIERA, HIERA-PUPPET' do |value| @cmd_options[:install] = value end opts.on('-m', '--modules URI', 'Select puppet module git install URI') do |value| @cmd_options[:modules] = value end opts.on '-q', '--[no-]quiet', 'Do not log output to STDOUT', '(default: false)' do |bool| @cmd_options[:quiet] = bool end opts.on '-x', '--[no-]xml', 'Emit JUnit XML reports on tests', '(default: false)' do |bool| @cmd_options[:xml] = bool end opts.on '--[no-]color', 'Do not display color in log output', '(default: true)' do |bool| @cmd_options[:color] = bool end opts.on '--[no-]debug', 'Enable full debugging', '(default: false)' do |bool| @cmd_options[:debug] = bool end opts.on '-d', '--[no-]dry-run', 'Report what would happen on targets', '(default: false)' do |bool| @cmd_options[:dry_run] = bool $dry_run = bool end opts.on '--fail-mode [MODE]', 'How should the harness react to errors/failures', 'Possible values:', 'fast (skip all subsequent tests, cleanup, exit)', 'stop (skip all subsequent tests, do no cleanup, exit immediately)' do |mode| @cmd_options[:fail_mode] = mode end opts.on '--[no-]ntp', 'Sync time on SUTs before testing', '(default: false)' do |bool| @cmd_options[:timesync] = bool end opts.on '--repo-proxy', 'Proxy packaging repositories on ubuntu, debian and solaris-11', '(default: false)' do @cmd_options[:repo_proxy] = true end opts.on '--add-el-extras', 'Add Extra Packages for Enterprise Linux (EPEL) repository to el-* hosts', '(default: false)' do @cmd_options[:add_el_extras] = true end opts.on('--version', 'Report currently running version of beaker' ) do @cmd_options[:version] = true end opts.on '-c', '--config FILE', 'DEPRECATED use --hosts' do |file| @cmd_options[:hosts_file] = file end opts.on('--help', 'Display this screen' ) do @cmd_options[:help] = true end end end |
Instance Method Details
#parse!(args = ARGV) ⇒ Hash
Parse an array of arguments into a Hash of options
185 186 187 188 |
# File 'lib/beaker/options/command_line_parser.rb', line 185 def parse!( args = ARGV ) @optparse.parse!(args) @cmd_options end |
#usage ⇒ String
Generate a string representing the supported arguments
197 198 199 |
# File 'lib/beaker/options/command_line_parser.rb', line 197 def usage @optparse.help end |