aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib/hbc/cli/internal_dump.rb
blob: ac1b2049392a37383d0182f910b87f1470cd8f16 (plain)
1
2
3
4
5
6
7
8
9
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
module Hbc
  class CLI
    class InternalDump < InternalUseBase
      def self.run(*arguments)
        cask_tokens = cask_tokens_from(arguments)
        raise CaskUnspecifiedError if cask_tokens.empty?
        retval = dump_casks(*cask_tokens)
        # retval is ternary: true/false/nil

        raise CaskError, "nothing to dump" if retval.nil?
        raise CaskError, "dump incomplete" unless retval
      end

      def self.dump_casks(*cask_tokens)
        Hbc.debug = true # Yuck. At the moment this is the only way to make dumps visible
        count = 0
        cask_tokens.each do |cask_token|
          begin
            cask = Hbc.load(cask_token)
            count += 1
            cask.dumpcask
          rescue StandardError => e
            opoo "#{cask_token} was not found or would not load: #{e}"
          end
        end
        count.zero? ? nil : count == cask_tokens.length
      end

      def self.help
        "dump the given Cask in YAML format"
      end
    end
  end
end