Class: Homebrew::DevCmd::Unpack

Inherits:
AbstractCommand show all
Includes:
FileUtils
Defined in:
dev-cmd/unpack.rb

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, #initialize, parser

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#runvoid

This method returns an undefined value.



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
# File 'dev-cmd/unpack.rb', line 35

def run
  formulae = args.named.to_formulae

  if (dir = args.destdir)
    unpack_dir = Pathname.new(dir).expand_path
    unpack_dir.mkpath
  else
    unpack_dir = Pathname.pwd
  end

  odie "Cannot write to #{unpack_dir}" unless unpack_dir.writable?

  formulae.each do |f|
    stage_dir = unpack_dir/"#{f.name}-#{f.version}"

    if stage_dir.exist?
      odie "Destination #{stage_dir} already exists!" unless args.force?

      rm_rf stage_dir
    end

    oh1 "Unpacking #{Formatter.identifier(f.full_name)} to: #{stage_dir}"

    # show messages about tar
    with_env VERBOSE: "1" do
      f.brew do
        f.patch if args.patch?
        cp_r getwd, stage_dir, preserve: true
      end
    end

    next unless args.git?

    ohai "Setting up Git repository"
    cd(stage_dir) do
      system "git", "init", "-q"
      system "git", "add", "-A"
      system "git", "commit", "-q", "-m", "brew-unpack"
    end
  end
end