Skip to content

Commit

Permalink
Merge pull request #2229 from rsteube/brew-abv
Browse files Browse the repository at this point in the history
brew: abv
  • Loading branch information
rsteube authored Feb 7, 2024
2 parents 8e52e7c + 97a271c commit dcfc034
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
43 changes: 29 additions & 14 deletions completers/brew_completer/cmd/abv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

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

Expand All @@ -14,19 +15,33 @@ var abvCmd = &cobra.Command{
func init() {
carapace.Gen(abvCmd).Standalone()

abvCmd.Flags().Bool("analytics", false, "List global Homebrew analytics data or, if specified, installation and build error data for <formula> (provided neither `HOMEBREW_NO_ANALYTICS` nor `HOMEBREW_NO_GITHUB_API` are set).")
abvCmd.Flags().Bool("cask", false, "Treat all named arguments as casks.")
abvCmd.Flags().Bool("category", false, "Which type of analytics data to retrieve. The value for <category> must be `install`, `install-on-request` or `build-error`; `cask-install` or `os-version` may be specified if <formula> is not. The default is `install`.")
abvCmd.Flags().Bool("days", false, "How many days of analytics data to retrieve. The value for <days> must be `30`, `90` or `365`. The default is `30`.")
abvCmd.Flags().Bool("debug", false, "Display any debugging information.")
abvCmd.Flags().Bool("eval-all", false, "Evaluate all available formulae and casks, whether installed or not, to print their JSON. Implied if `HOMEBREW_EVAL_ALL` is set.")
abvCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae.")
abvCmd.Flags().Bool("github", false, "Open the GitHub source page for <formula> and <cask> in a browser. To view the history locally: `brew log -p` <formula> or <cask>")
abvCmd.Flags().Bool("help", false, "Show this message.")
abvCmd.Flags().Bool("installed", false, "Print JSON of formulae that are currently installed.")
abvCmd.Flags().Bool("json", false, "Print a JSON representation. Currently the default value for <version> is `v1` for <formula>. For <formula> and <cask> use `v2`. See the docs for examples of using the JSON output: <https://docs.brew.sh/Querying-Brew>")
abvCmd.Flags().Bool("quiet", false, "Make some output more quiet.")
abvCmd.Flags().Bool("variations", false, "Include the variations hash in each formula's JSON output.")
abvCmd.Flags().Bool("verbose", false, "Show more verbose analytics data for <formula>.")
abvCmd.Flags().Bool("analytics", false, "List global Homebrew analytics data")
abvCmd.Flags().Bool("cask", false, "Treat all named arguments as casks")
abvCmd.Flags().String("category", "", "Which type of analytics data to retrieve")
abvCmd.Flags().String("days", "", "How many days of analytics data to retrieve")
abvCmd.Flags().Bool("debug", false, "Display any debugging information")
abvCmd.Flags().Bool("eval-all", false, "Evaluate all available formulae and casks")
abvCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae")
abvCmd.Flags().Bool("github", false, "Open the GitHub source page for <formula> and <cask> in a browser")
abvCmd.Flags().Bool("help", false, "Show this message")
abvCmd.Flags().Bool("installed", false, "Print JSON of formulae that are currently installed")
abvCmd.Flags().Bool("json", false, "Print a JSON representation")
abvCmd.Flags().Bool("quiet", false, "Make some output more quiet")
abvCmd.Flags().Bool("variations", false, "Include the variations hash in each formula's JSON output")
abvCmd.Flags().Bool("verbose", false, "Show more verbose analytics data for <formula>")
rootCmd.AddCommand(abvCmd)

abvCmd.MarkFlagsMutuallyExclusive("cask", "formula")

carapace.Gen(abvCmd).FlagCompletion(carapace.ActionMap{
"category": carapace.ActionValues("install", "install-on-request", "build-error", "cask-install", "os-version"),
"days": carapace.ActionValues("30", "90", "365"),
})

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

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionAllCasks completes all casks
func ActionAllCasks() carapace.Action {
return carapace.ActionExecCommand("brew", "casks")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
return carapace.ActionValues(lines[:len(lines)-1]...)
}).Tag("casks")
}
15 changes: 15 additions & 0 deletions pkg/actions/tools/brew/formula.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package brew

import (
"strings"

"github.com/rsteube/carapace"
)

// ActionAllFormulae completes all formulae
func ActionAllFormulae() carapace.Action {
return carapace.ActionExecCommand("brew", "formulae")(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
return carapace.ActionValues(lines[:len(lines)-1]...)
}).Tag("formulae")
}

0 comments on commit dcfc034

Please sign in to comment.