Class: FTest::CLI::ArgvParser

Inherits:
Object
  • Object
show all
Defined in:
lib/ftest/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, options) ⇒ ArgvParser

Returns a new instance of ArgvParser.



123
124
125
126
# File 'lib/ftest/cli.rb', line 123

def initialize argv, options
  @argv = argv
  @options = options
end

Class Method Details

.call(argv) ⇒ Object



116
117
118
119
120
121
# File 'lib/ftest/cli.rb', line 116

def self.call argv
  options = Options.build
  parser = ArgvParser.new argv, options
  parser.()
  options
end

Instance Method Details

#add_pathsObject



133
134
135
136
137
138
# File 'lib/ftest/cli.rb', line 133

def add_paths
  @argv << "tests" if @argv.empty?
  @argv.each do |path|
    @options.add_path path
  end
end

#callObject



128
129
130
131
# File 'lib/ftest/cli.rb', line 128

def call
  parse_options
  add_paths
end

#parse_optionsObject



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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/ftest/cli.rb', line 140

def parse_options
  OptionParser.new do |opts|
    opts.banner = <<-BANNER
Usage: #{program_name} [options] [PATH1] [PATH2] … [PATHn]

If no PATH(s) are specified, ./tests is assumed

    BANNER

    opts.on "-b", "--full-backtrace", "Do not filter assertion stack traces" do
      @options.full_backtrace
    end

    opts.on "-f", "--fail-fast", "When any test script fails, exit immediately" do
      @options.fail_fast
    end

    opts.on "-h", "--help", "Print this message and exit successfully" do
      puts opts
      exit 0
    end

    opts.on "-m", "--monkeypatch", "Turn on monkeypatching (equivalent to `require \"ftest/script\"'" do
      require "ftest/script"
    end

    opts.on "-n", "--num=COUNT", "Max number of sub processes to run concurrently" do |num|
      @options.child_count = num
    end

    opts.on "-q", "--quiet", "Reduces log verbosity" do
      @options.quiet
    end

    opts.on "-r", "--reverse-traces", "Reverse the order of stack traces" do
      @options.reverse_backtraces
    end

    opts.on "-V", "--version", "Print version and exit successfully" do
      spec = Gem.loaded_specs["ftest"]
      version = if spec then spec.version else "(local)" end
      puts "Version: #{version}"
      exit 0
    end

    opts.on "-v", "--verbose", "Increases log verbosity" do
      @options.verbose
    end
  end.parse! @argv
end

#program_nameObject



191
192
193
# File 'lib/ftest/cli.rb', line 191

def program_name
  File.basename $PROGRAM_NAME
end