Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew: audit #2232

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),
},
}
}
}
Loading