Class: Pendaxes::CommandLine::Oneshot

Inherits:
Object
  • Object
show all
Defined in:
lib/pendaxes/command_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Oneshot

Returns a new instance of Oneshot.



193
194
195
# File 'lib/pendaxes/command_line.rb', line 193

def initialize(*args)
  @args = args
end

Instance Method Details

#runObject



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/pendaxes/command_line.rb', line 197

def run
  quiet = false
  path = Dir.pwd
  reporter = :text

  OptionParser.new do |opts|
    opts.on('-q', '--quiet', 'Turn off progress output.') do
      quiet = true
    end

    opts.on('-d DIR', '--repo DIR', 'Specify path to working copy of git.') do |dir|
      path = dir
    end

    opts.on('-r REPORTER', '--reporter REPORTER', 'Specify reporter') do |name|
      reporter = name.to_sym
    end

    opts.on_tail('--help', 'Show this help') do
      return usage
    end
  end.parse!(@args)

  if @args.empty?
    return usage
  end

  workspace = Workspace.new(path: path)

  files = workspace.dive do
    @args.map { |pattern|
      sub_files = Dir[pattern].map do |file_or_directory|
        if FileTest.file?(file_or_directory)
          file_or_directory
        elsif FileTest.directory?(file_or_directory)
          Dir[File.join(file_or_directory, '**', '*_spec.rb')]
        end
      end
      if sub_files.empty?
        abort "#{$0}: #{pattern}: No such file or directory"
      end
      sub_files
    }.flatten.map { |_| File.expand_path(_) }
  end

  $stderr.puts '=> Detecting...' unless quiet
  pendings = Detector.find(:rspec).new(workspace, out: quiet ? nil : $stderr, pattern: files).detect
  $stderr.puts '=> Total Result:' unless quiet

  notificator = Notificator.find(:terminal).new(
    out: $stdout, include_allowed: true,
    reporter: {use: reporter, include_allowed: true}
  )
  notificator.add pendings
  notificator.notify

  0
end

#usageObject



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/pendaxes/command_line.rb', line 256

def usage
  $stderr.puts "Usage: pendaxes-oneshot [--help] [-q|--quiet] [-d DIR|--repo=DIR] [-r REPORTER|--reporter REPORTER] file_or_directory [file_or_directory ...]"
  $stderr.puts ""
  $stderr.puts "file_or_directory:"
  $stderr.puts "  File name, pattern or directory name to detect pendings."
  $stderr.puts "  if directory name given, will use *_spec.rb files in that directory (recursive)."
  $stderr.puts ""
  $stderr.puts "  NOTE: Files should be managed by git."
  $stderr.puts ""
  $stderr.puts "--help: Show this help and quit."
  $stderr.puts "--quiet, -q: Turn off progress output."
  $stderr.puts "--repo, -d: Specify path to working copy of git repository. (default: current directory)"
  $stderr.puts "--reporter, -r: Specify reporter. (Default: text)"
  0
end