Class: Cask::Cmd::Audit Private

Inherits:
AbstractCommand show all
Extended by:
T::Sig
Defined in:
cask/cmd/audit.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Cask implementation of the brew audit command.

Constant Summary

Constants inherited from AbstractCommand

Cask::Cmd::AbstractCommand::OPTIONS

Instance Attribute Summary

Attributes inherited from AbstractCommand

#args

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

abstract?, command_name, help, #initialize, run, short_description, visible?

Methods included from Homebrew::Search

#query_regexp, #search_casks, #search_descriptions, #search_formulae, #search_taps

Methods included from Homebrew::Search::Extension

#search_casks, #search_descriptions

Constructor Details

This class inherits a constructor from Cask::Cmd::AbstractCommand

Class Method Details

.audit_casks(*casks, download: nil, appcast: nil, online: nil, strict: nil, new_cask: nil, token_conflicts: nil, quarantine: nil, any_named_args: nil, language: nil, display_passes: nil, display_failures_only: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'cask/cmd/audit.rb', line 68

def self.audit_casks(
  *casks,
  download: nil,
  appcast: nil,
  online: nil,
  strict: nil,
  new_cask: nil,
  token_conflicts: nil,
  quarantine: nil,
  any_named_args: nil,
  language: nil,
  display_passes: nil,
  display_failures_only: nil
)
  options = {
    audit_download:        download,
    audit_appcast:         appcast,
    audit_online:          online,
    audit_strict:          strict,
    audit_new_cask:        new_cask,
    audit_token_conflicts: token_conflicts,
    quarantine:            quarantine,
    language:              language,
    any_named_args:        any_named_args,
    display_passes:        display_passes,
    display_failures_only: display_failures_only,
  }.compact

  options[:quarantine] = true if options[:quarantine].nil?

  Homebrew.auditing = true

  require "cask/auditor"

  casks.map do |cask|
    odebug "Auditing Cask #{cask}"
    [cask.sourcefile_path, Auditor.audit(cask, **options)]
  end.to_h
end

.parserObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'cask/cmd/audit.rb', line 14

def self.parser
  super do
    switch "--[no-]download",
           description: "Audit the downloaded file"
    switch "--[no-]appcast",
           description: "Audit the appcast"
    switch "--[no-]token-conflicts",
           description: "Audit for token conflicts"
    switch "--[no-]strict",
           description: "Run additional, stricter style checks"
    switch "--[no-]online",
           description: "Run additional, slower style checks that require a network connection"
    switch "--new-cask",
           description: "Run various additional style checks to determine if a new cask is eligible " \
                        "for Homebrew. This should be used when creating new casks and implies " \
                        "`--strict` and `--online`"
    switch "--display-failures-only",
           description: "Only display casks that fail the audit. This is the default for formulae."
  end
end

Instance Method Details

#runvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Raises:



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
# File 'cask/cmd/audit.rb', line 36

def run
  casks = args.named.flat_map do |name|
    next name if File.exist?(name)
    next Tap.fetch(name).cask_files if name.count("/") == 1

    name
  end
  casks = casks.map { |c| CaskLoader.load(c, config: Config.from_args(args)) }
  any_named_args = casks.any?
  casks = Cask.to_a if casks.empty?

  results = self.class.audit_casks(
    *casks,
    download:              args.download?,
    appcast:               args.appcast?,
    online:                args.online?,
    strict:                args.strict?,
    new_cask:              args.new_cask?,
    token_conflicts:       args.token_conflicts?,
    quarantine:            args.quarantine?,
    any_named_args:        any_named_args,
    language:              args.language,
    display_passes:        args.verbose? || args.named.count == 1,
    display_failures_only: args.display_failures_only?,
  )

  failed_casks = results.reject { |_, result| result[:errors].empty? }.map(&:first)
  return if failed_casks.empty?

  raise CaskError, "audit failed for casks: #{failed_casks.join(" ")}"
end