class StartupTime::Options
StartupTime::Options
- a struct-like interface to the app options set or overridden on the command line
Constants
- BUILD_DIR
- DEFAULT_DURATION
- MINIMUM_DURATION
- Spec
Attributes
action[R]
build_dir[R]
format[R]
rounds[R]
verbosity[R]
Public Class Methods
new(args)
click to toggle source
# File lib/startup_time/options.rb, line 21 def initialize(args) @action = :benchmark @build_dir = BUILD_DIR @duration = DEFAULT_DURATION @format = :default @parser = nil @rounds = nil @spec = nil @verbosity = :default parse! args end
Public Instance Methods
spec()
click to toggle source
# File lib/startup_time/options.rb, line 34 def spec @spec ||= if @rounds Spec.with(type: :count, value: @rounds) else Spec.with(type: :duration, value: @duration) end end
usage()
click to toggle source
the usage message (string) generated by the option parser for this tool
# File lib/startup_time/options.rb, line 43 def usage @parser.to_s end
Private Instance Methods
parse!(args)
click to toggle source
process the command-line options and assign values to the corresponding instance variables
# File lib/startup_time/options.rb, line 51 def parse!(args) @parser = OptionParser.new do |opts| opts.on( '-c', '--count', '--rounds INTEGER', Integer, 'The number of times to run each program' ) do |value| @rounds = value end opts.on( '--clean', 'Remove the build directory and exit', '(targets will be recompiled on the next run)' ) do @action = :clean end opts.on( '-d', '--dir PATH', String, 'Specify the build directory', "(default: #{BUILD_DIR})" ) do |value| @build_dir = value end opts.on( '-h', '--help', 'Show this help message and exit' ) do @action = :help end opts.on( '-H', '--help-only', '--help-omit', 'Show the IDs and groups that can be passed to --only and --omit' ) do @action = :show_ids end opts.on( '-j', '--json', 'Output the results in JSON format (implies --quiet)' ) do @format = :json @verbosity = :quiet end opts.on( '-o', '--only LIST', Array, # comma-separated strings 'Only run the specified tests (comma-separated list of IDs/groups)' ) do |values| values.each { |value| registry.only(value.strip) } end opts.on( '-O', '--omit LIST', Array, # comma-separated strings "Don't run the specified tests (comma-separated list of IDs/groups)" ) do |values| values.each { |value| registry.omit(value.strip) } end opts.on( '-q', '--quiet', 'Suppress all inessential output' ) do @verbosity = :quiet end opts.on( '-t', '--time INTEGER', Integer, 'Specify the minimum number of seconds to run tests for', "(minimum: #{MINIMUM_DURATION}, default: #{DEFAULT_DURATION})" ) do |value| @duration = [value, MINIMUM_DURATION].max end opts.on( '-v', '--verbose', 'Enable verbose logging' ) do @verbosity = :verbose end opts.on( '-V', '--version', 'Display the version and exit' ) do @action = :version end end @parser.parse!(args) end