Skip to content

Commit

Permalink
brew: audit
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 7, 2024
1 parent e71bc2b commit ff3577f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 24 deletions.
72 changes: 48 additions & 24 deletions completers/brew_completer/cmd/audit.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package cmd

import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/brew"
"github.com/rsteube/carapace-bin/pkg/actions/tools/gh"
"github.com/spf13/cobra"
)

Expand All @@ -15,31 +19,51 @@ var auditCmd = &cobra.Command{
func init() {
carapace.Gen(auditCmd).Standalone()

auditCmd.Flags().Bool("arch", false, "Audit the given CPU architecture. (Pass `all` to audit all architectures.)")
auditCmd.Flags().Bool("audit-debug", false, "Enable debugging and profiling of audit methods.")
auditCmd.Flags().Bool("cask", false, "Treat all named arguments as casks.")
auditCmd.Flags().Bool("debug", false, "Display any debugging information.")
auditCmd.Flags().Bool("display-filename", false, "Prefix every line of output with the file or formula name being audited, to make output easy to grep.")
auditCmd.Flags().Bool("eval-all", false, "Evaluate all available formulae and casks, whether installed or not, to audit them. Implied if `HOMEBREW_EVAL_ALL` is set.")
auditCmd.Flags().Bool("except", false, "Specify a comma-separated <method> list to skip running the methods named `audit_`<method>.")
auditCmd.Flags().Bool("except-cops", false, "Specify a comma-separated <cops> list to skip checking for violations of the listed RuboCop cops.")
auditCmd.Flags().Bool("fix", false, "Fix style violations automatically using RuboCop's auto-correct feature.")
auditCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae.")
auditCmd.Flags().Bool("git", false, "Run additional, slower style checks that navigate the Git repository.")
auditCmd.Flags().Bool("help", false, "Show this message.")
auditCmd.Flags().Bool("installed", false, "Only check formulae and casks that are currently installed.")
auditCmd.Flags().Bool("new", false, "Run various additional style checks to determine if a new formula or cask is eligible for Homebrew. This should be used when creating new formulae or casks and implies `--strict` and `--online`.")
auditCmd.Flags().Bool("arch", false, "Audit the given CPU architecture")
auditCmd.Flags().Bool("audit-debug", false, "Enable debugging and profiling of audit methods")
auditCmd.Flags().Bool("cask", false, "Treat all named arguments as casks")
auditCmd.Flags().Bool("debug", false, "Display any debugging information")
auditCmd.Flags().Bool("display-filename", false, "Prefix every line of output with the file or formula name being audited")
auditCmd.Flags().Bool("eval-all", false, "Evaluate all available formulae and casks")
auditCmd.Flags().String("except", "", "Specify a comma-separated <method> list to skip")
auditCmd.Flags().String("except-cops", "", "Specify a comma-separated <cops> list to skip checking")
auditCmd.Flags().Bool("fix", false, "Fix style violations automatically using RuboCop's auto-correct feature")
auditCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae")
auditCmd.Flags().Bool("git", false, "Run additional, slower style checks that navigate the Git repository")
auditCmd.Flags().Bool("help", false, "Show this message")
auditCmd.Flags().Bool("installed", false, "Only check formulae and casks that are currently installed")
auditCmd.Flags().Bool("new", false, "Run various additional style checks")
auditCmd.Flags().Bool("no-signing", false, "Audit for signed apps, which are required on ARM")
auditCmd.Flags().Bool("online", false, "Run additional, slower style checks that require a network connection.")
auditCmd.Flags().Bool("only", false, "Specify a comma-separated <method> list to only run the methods named `audit_`<method>.")
auditCmd.Flags().Bool("only-cops", false, "Specify a comma-separated <cops> list to check for violations of only the listed RuboCop cops.")
auditCmd.Flags().Bool("os", false, "Audit the given operating system. (Pass `all` to audit all operating systems.)")
auditCmd.Flags().Bool("quiet", false, "Make some output more quiet.")
auditCmd.Flags().Bool("online", false, "Run additional, slower style checks that require a network connection")
auditCmd.Flags().String("only", "", "Specify a comma-separated <method> list to only run")
auditCmd.Flags().String("only-cops", "", "Specify a comma-separated <cops> list to check")
auditCmd.Flags().String("os", "", "Audit the given operating system")
auditCmd.Flags().Bool("quiet", false, "Make some output more quiet")
auditCmd.Flags().Bool("signing", false, "Audit for signed apps, which are required on ARM")
auditCmd.Flags().Bool("skip-style", false, "Skip running non-RuboCop style checks. Useful if you plan on running `brew style` separately. Enabled by default unless a formula is specified by name.")
auditCmd.Flags().Bool("strict", false, "Run additional, stricter style checks.")
auditCmd.Flags().Bool("tap", false, "Check the formulae within the given tap, specified as <user>`/`<repo>.")
auditCmd.Flags().Bool("token-conflicts", false, "Audit for token conflicts.")
auditCmd.Flags().Bool("verbose", false, "Make some output more verbose.")
auditCmd.Flags().Bool("skip-style", false, "Skip running non-RuboCop style checks")
auditCmd.Flags().Bool("strict", false, "Run additional, stricter style checks")
auditCmd.Flags().String("tap", "", "Check the formulae within the given tap, specified as <user>`/`<repo>")
auditCmd.Flags().Bool("token-conflicts", false, "Audit for token conflicts")
auditCmd.Flags().Bool("verbose", false, "Make some output more verbose")
rootCmd.AddCommand(auditCmd)

// TODO flag completion
carapace.Gen(auditCmd).FlagCompletion(carapace.ActionMap{
"tap": gh.ActionOwnerRepositories(gh.HostOpts{}),
})

carapace.Gen(auditCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if f := auditCmd.Flag("tap"); f.Changed {
if owner, repo, ok := strings.Cut(f.Value.String(), "/"); ok {
return gh.ActionContents(gh.ContentOpts{Owner: owner, Name: repo}) // TODO list remote formulae
}
}

return carapace.Batch(
brew.ActionAllCasks().Unless(func(c carapace.Context) bool { return auditCmd.Flag("formula").Changed }),
brew.ActionAllFormulae().Unless(func(c carapace.Context) bool { return auditCmd.Flag("cask").Changed }),
).ToA().FilterArgs()
}),
)
}
20 changes: 20 additions & 0 deletions pkg/actions/env/homebrew.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package env

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/conditions"
)

func init() {
knownVariables["homebrew"] = func() variables {
return variables{
Condition: conditions.ConditionPath("brew"),
Variables: map[string]string{
"HOMEBREW_EVAL_ALL": "Evaluate all available formulae and casks",
},
VariableCompletion: map[string]carapace.Action{
"HOMEBREW_EVAL_ALL": carapace.ActionValues("1"),
},
}
}
}

0 comments on commit ff3577f

Please sign in to comment.