Module: Hashira::CLI::Needs

Defined in:
lib/hashira/cli/needs.rb

Constant Summary collapse

DIAGRAMS =
%i[dot mermaid].freeze

Class Method Summary collapse

Class Method Details

.check(options) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/hashira/cli/needs.rb', line 10

def check(options)
  mode = options.mode
  skip = options.skip
  drawing(mode, skip)
  gate(options.fail_on, skip)
  shaping(options, mode)
end

.compacting(mode) ⇒ Object

Raises:



29
30
31
# File 'lib/hashira/cli/needs.rb', line 29

def compacting(mode)
  raise(Hashira::Error, "--compact shapes JSON, but this run emits #{mode}") unless mode == :json
end

.drawing(mode, skip) ⇒ Object

Raises:



33
34
35
36
# File 'lib/hashira/cli/needs.rb', line 33

def drawing(mode, skip)
  return unless DIAGRAMS.include?(mode) && skip.include?(:coupling)
  raise(Hashira::Error, "--format #{mode} draws the coupling graph, but --skip coupling drops it")
end

.focusing(mode) ⇒ Object

Raises:



23
24
25
26
27
# File 'lib/hashira/cli/needs.rb', line 23

def focusing(mode)
  raise(Hashira::Error, "--only narrows the findings, but --update-baseline records them all") if mode == :update
  return unless DIAGRAMS.include?(mode)
  raise(Hashira::Error, "--format #{mode} draws the coupling graph, which --only cannot narrow")
end

.gate(fail_on, skip) ⇒ Object

Raises:



38
39
40
41
42
# File 'lib/hashira/cli/needs.rb', line 38

def gate(fail_on, skip)
  blind = fail_on.find { skip.include?(owner(it)) }
  return unless blind
  raise(Hashira::Error, "--fail-on #{blind} needs the #{owner(blind)} analyzer, but --skip drops it")
end

.owner(kind) ⇒ Object



44
# File 'lib/hashira/cli/needs.rb', line 44

def owner(kind) = Hashira::CLI::FailOn.owner(kind)

.shaping(options, mode) ⇒ Object



18
19
20
21
# File 'lib/hashira/cli/needs.rb', line 18

def shaping(options, mode)
  compacting(mode) if options.compact
  focusing(mode) unless options.only.empty?
end