Class: GitFit::InstallCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/git_fit/cli/install_cli.rb

Instance Method Summary collapse

Instance Method Details

#actions(family = nil) ⇒ Object



10
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
# File 'lib/git_fit/cli/install_cli.rb', line 10

def actions(family = nil)
  check = options[:check]
  dry_run = options[:"dry-run"]

  if check && dry_run
    say "Error: --check and --dry-run are mutually exclusive", :red
    raise Thor::Error, "Cannot use --check and --dry-run together"
  end

  results = GitFit::Install::Actions.install(family, check: check, dry_run: dry_run)

  if dry_run
    results.each do |r|
      say "Would write: #{r[:path]}", :cyan
      say r[:content], :cyan
    end
    return
  end

  if check
    mismatches = results.select { |r| r[:mismatch] }
    if mismatches.any?
      mismatches.each do |r|
        say "DIFF: #{r[:path]}", :red
        puts r[:diff]
      end
      raise Thor::Error, "Install check failed: #{mismatches.size} file(s) differ from template"
    else
      results.each { |r| say_status :ok, r[:path], :green }
      say "All #{results.size} files match templates", :green
    end
    return
  end

  results.each { |r| say_status :created, r[:path], :green }
end