Class: Lapidarist::CLI

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
7
8
9
# File 'lib/lapidarist/cli.rb', line 3

def initialize(args)
  @args = args
  @git = GitCommand.new
  @test = TestCommand.new
  @update = Update.new
  @sha = Sha.new
end

Instance Method Details

#runObject



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
# File 'lib/lapidarist/cli.rb', line 11

def run
  Options.new(args).parse
  Lapidarist.logger.header('Starting lapidarist')
  trap_interrupt

  unless git.clean?
    Lapidarist.logger.footer('stopping, there are uncommitted changes')
    return STATUS_ERROR
  end

  sha.record_good
  gems = Lapidarist::Outdated.new.run

  status = nil
  attempt = 0
  loop do
    attempt += 1
    Lapidarist.logger.header("Attempt ##{attempt}")

    if gems.outdated.none?
      Lapidarist.logger.footer('stopping, there are no applicable outdated gems')
      status = Status.new(gems, attempt)
      break
    end

    updated_gems = update.run(gems, attempt)

    if sha.new_commit_count.zero?
      Lapidarist.logger.footer('nothing updated, trying again')
      gems = gems.merge(updated_gems)
      next
    end

    Lapidarist.logger.header("Testing gem updates")
    if test.success?
      Lapidarist.logger.footer('test passed, nothing left to do')
      gems = gems.merge(updated_gems)
      status = Status.new(gems, attempt)
      break
    else
      Lapidarist.logger.footer('test failed')
    end

    failed_gem = Lapidarist::FindFailure.new(
      gems: updated_gems,
      attempt: attempt,
      last_good_sha: sha.last_good
    ).run
    gems = gems.merge(updated_gems.take(sha.new_commit_count)).merge(failed_gem)
    sha.record_good

    if Lapidarist.config.debug
      Summary.new(gems).display_debug
    end
  end

  Summary.new(gems).display
  return status.to_i

rescue OptionParser::InvalidOption => e
  warn e.message
  warn 'For usage information, use --help'
  return STATUS_ERROR
rescue Lapidarist::Abort => e
  git.reset_hard(sha.last_good)
  Summary.new(gems).display
  return STATUS_ERROR
end

#trap_interruptObject



80
81
82
83
84
85
86
87
88
89
# File 'lib/lapidarist/cli.rb', line 80

def trap_interrupt
  Signal.trap('INT') do
    warn
    warn 'Cleaning up and exiting... Interrupt again to exit immediately.'

    Lapidarist.threads.stop

    raise Lapidarist::Abort
  end
end