Skip to content

Commit

Permalink
Merge pull request #852 from rsteube/add-brew
Browse files Browse the repository at this point in the history
added brew
  • Loading branch information
rsteube authored Jan 25, 2022
2 parents 33db2de + a11f95c commit 77d3323
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 0 deletions.
22 changes: 22 additions & 0 deletions completers/brew_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package action

import (
"github.com/spf13/cobra"
)

func defaultArgs(cmd *cobra.Command) []string {
args := make([]string, 0)

if flag := cmd.Flag("formula"); flag != nil && flag.Changed {
args = append(args, "--formula")
} else if flag := cmd.Flag("formulae"); flag != nil && flag.Changed {
args = append(args, "--formulae")
}

if flag := cmd.Flag("cask"); flag != nil && flag.Changed {
args = append(args, "--cask")
} else if flag := cmd.Flag("casks"); flag != nil && flag.Changed {
args = append(args, "--casks")
}
return args
}
18 changes: 18 additions & 0 deletions completers/brew_completer/cmd/action/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package action

import (
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

func ActionList(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
args := append([]string{"list"}, defaultArgs(cmd)...)
return carapace.ActionExecCommand("brew", args...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
return carapace.ActionValues(lines[:len(lines)-1]...)
})
})
}
31 changes: 31 additions & 0 deletions completers/brew_completer/cmd/action/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package action

import (
"fmt"
"strings"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

func ActionSearch(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.CallbackValue) < 2 {
return carapace.ActionMessage("search needs at least 2 characters")
}

args := append([]string{"search"}, defaultArgs(cmd)...)
args = append(args, fmt.Sprintf("/^%v/", c.CallbackValue))
return carapace.ActionExecCommand("brew", args...)(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")

vals := make([]string, 0)
for _, line := range lines {
if !strings.HasPrefix(line, "==>") {
vals = append(vals, line)
}
}
return carapace.ActionValues(vals...)
})
})
}
22 changes: 22 additions & 0 deletions completers/brew_completer/cmd/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var configCmd = &cobra.Command{
Use: "config",
Short: "Show Homebrew and system configuration info useful for debugging",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(configCmd).Standalone()

configCmd.Flags().BoolP("debug", "d", false, "Display any debugging information.")
configCmd.Flags().BoolP("help", "h", false, "Show this message.")
configCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
configCmd.Flags().BoolP("verbose", "v", false, "Make some output more verbose.")
rootCmd.AddCommand(configCmd)
}
40 changes: 40 additions & 0 deletions completers/brew_completer/cmd/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var createCmd = &cobra.Command{
Use: "create",
Short: "Generate a formula or a cask for the downloadable file at URL",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(createCmd).Standalone()

createCmd.Flags().Bool("HEAD", false, "Indicate that URL points to the package's repository rather than a file.")
createCmd.Flags().Bool("autotools", false, "Create a basic template for an Autotools-style build.")
createCmd.Flags().Bool("cask", false, "Create a basic template for a cask.")
createCmd.Flags().Bool("cmake", false, "Create a basic template for a CMake-style build.")
createCmd.Flags().Bool("crystal", false, "Create a basic template for a Crystal build.")
createCmd.Flags().BoolP("debug", "d", false, "Display any debugging information.")
createCmd.Flags().BoolP("force", "f", false, "Ignore errors for disallowed formula names")
createCmd.Flags().Bool("go", false, "Create a basic template for a Go build.")
createCmd.Flags().BoolP("help", "h", false, "Show this message.")
createCmd.Flags().Bool("meson", false, "Create a basic template for a Meson-style build.")
createCmd.Flags().Bool("no-fetch", false, "Homebrew will not download URL to the cache")
createCmd.Flags().Bool("node", false, "Create a basic template for a Node build.")
createCmd.Flags().Bool("perl", false, "Create a basic template for a Perl build.")
createCmd.Flags().Bool("python", false, "Create a basic template for a Python build.")
createCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
createCmd.Flags().Bool("ruby", false, "Create a basic template for a Ruby build.")
createCmd.Flags().Bool("rust", false, "Create a basic template for a Rust build.")
createCmd.Flags().Bool("set-license", false, "Explicitly set the license of the new formula.")
createCmd.Flags().Bool("set-name", false, "Explicitly set the name of the new formula or cask.")
createCmd.Flags().Bool("set-version", false, "Explicitly set the version of the new formula or cask.")
createCmd.Flags().Bool("tap", false, "Generate the new formula within the given tap")
createCmd.Flags().BoolP("verbose", "v", false, "Make some output more verbose.")
rootCmd.AddCommand(createCmd)
}
24 changes: 24 additions & 0 deletions completers/brew_completer/cmd/doctor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var doctorCmd = &cobra.Command{
Use: "doctor",
Short: "Check your system for potential problems",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(doctorCmd).Standalone()

doctorCmd.Flags().BoolP("audit-debug", "D", false, "Enable debugging and profiling of audit methods.")
doctorCmd.Flags().BoolP("debug", "d", false, "Display any debugging information.")
doctorCmd.Flags().BoolP("help", "h", false, "Show this message.")
doctorCmd.Flags().Bool("list-checks", false, "List all audit methods")
doctorCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
doctorCmd.Flags().BoolP("verbose", "v", false, "Make some output more verbose.")
rootCmd.AddCommand(doctorCmd)
}
32 changes: 32 additions & 0 deletions completers/brew_completer/cmd/edit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/brew_completer/cmd/action"
"github.com/spf13/cobra"
)

var editCmd = &cobra.Command{
Use: "edit",
Short: "Open a formula or cask in the editor",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(editCmd).Standalone()

editCmd.Flags().Bool("cask", false, "Treat all named arguments as casks.")
editCmd.Flags().Bool("casks", false, "Treat all named arguments as casks.")
editCmd.Flags().BoolP("debug", "d", false, "Display any debugging information.")
editCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae.")
editCmd.Flags().Bool("formulae", false, "Treat all named arguments as formulae.")
editCmd.Flags().BoolP("help", "h", false, "Show this message.")
editCmd.Flags().Bool("print-path", false, "Print the file path to be edited")
editCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
editCmd.Flags().BoolP("verbose", "v", false, "Make some output more verbose.")
rootCmd.AddCommand(editCmd)

carapace.Gen(editCmd).PositionalAnyCompletion(
action.ActionList(editCmd),
)
}
42 changes: 42 additions & 0 deletions completers/brew_completer/cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/brew_completer/cmd/action"
"github.com/spf13/cobra"
)

var infoCmd = &cobra.Command{
Use: "info",
Short: "Display brief statistics for your Homebrew installation",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(infoCmd).Standalone()

infoCmd.Flags().Bool("all", false, "Print JSON of all available formulae")
infoCmd.Flags().Bool("analytics", false, "List global Homebrew analytics data")
infoCmd.Flags().Bool("cask", false, "Treat all named arguments as casks")
infoCmd.Flags().Bool("casks", false, "Treat all named arguments as casks")
infoCmd.Flags().String("category", "", "Which type of analytics data to retrieve")
infoCmd.Flags().String("days", "", "How many days of analytics data to retrieve")
infoCmd.Flags().BoolP("debug", "d", false, "Display any debugging information")
infoCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae")
infoCmd.Flags().Bool("formulae", false, "Treat all named arguments as formulae")
infoCmd.Flags().Bool("github", false, "Open the GitHub source page for formula and cask in a browser")
infoCmd.Flags().BoolP("help", "h", false, "Show this message")
infoCmd.Flags().Bool("installed", false, "Print JSON of formulae that are currently installed")
infoCmd.Flags().Bool("json", false, "Print a JSON representation")
infoCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet")
infoCmd.Flags().BoolP("verbose", "v", false, "Show more verbose analytics data for formula")
rootCmd.AddCommand(infoCmd)

carapace.Gen(infoCmd).FlagCompletion(carapace.ActionMap{
"category": carapace.ActionValues("install", "install-on-request", "build-error"),
})

carapace.Gen(installCmd).PositionalAnyCompletion(
action.ActionSearch(installCmd),
)
}
85 changes: 85 additions & 0 deletions completers/brew_completer/cmd/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/brew_completer/cmd/action"
"github.com/spf13/cobra"
)

var installCmd = &cobra.Command{
Use: "install",
Short: "Install a formula or cask",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(installCmd).Standalone()

installCmd.Flags().Bool("HEAD", false, "If formula defines it, install the HEAD version")
installCmd.Flags().String("appdir", "", "Target location for Applications")
installCmd.Flags().String("audio-unit-plugindir", "", "Target location for Audio Unit Plugins")
installCmd.Flags().Bool("binaries", false, "Enable linking of helper executables")
installCmd.Flags().String("bottle-arch", "", "Optimise bottles for the specified architecture")
installCmd.Flags().Bool("build-bottle", false, "Prepare the formula for eventual bottling during installation")
installCmd.Flags().BoolP("build-from-source", "s", false, "Compile formula from source even if a bottle is provided")
installCmd.Flags().Bool("cask", false, "Treat all named arguments as casks")
installCmd.Flags().Bool("casks", false, "Treat all named arguments as casks")
installCmd.Flags().Bool("cc", false, "Attempt to compile using the specified compiler")
installCmd.Flags().String("colorpickerdir", "", "Target location for Color Pickers")
installCmd.Flags().BoolP("debug", "d", false, "If brewing fails, open an interactive debugging session")
installCmd.Flags().String("dictionarydir", "", "Target location for Dictionaries (default:")
installCmd.Flags().Bool("display-times", false, "Print install times for each package at the end of the run")
installCmd.Flags().Bool("fetch-HEAD", false, "Fetch the upstream repository to detect if the HEAD installation of the formula is outdated")
installCmd.Flags().String("fontdir", "", "Target location for Fonts (default:")
installCmd.Flags().BoolP("force", "f", false, "Install formulae without checking for previously installed")
installCmd.Flags().Bool("force-bottle", false, "Install from a bottle even if it would not normally be used for installation")
installCmd.Flags().Bool("formula", false, "Treat all named arguments as formulae")
installCmd.Flags().Bool("formulae", false, "Treat all named arguments as formulae")
installCmd.Flags().BoolP("git", "g", false, "Create a Git repository")
installCmd.Flags().BoolP("help", "h", false, "Show this message.")
installCmd.Flags().Bool("ignore-dependencies", false, "An unsupported Homebrew development flag to skip installing any dependencies")
installCmd.Flags().Bool("include-test", false, "Install testing dependencies required to run brew test formula")
installCmd.Flags().String("input-methoddir", "", "Target location for Input Methods (default:")
installCmd.Flags().BoolP("interactive", "i", false, "Download and patch formula, then open a shell")
installCmd.Flags().String("internet-plugindir", "", "Target location for Internet Plugins")
installCmd.Flags().Bool("keep-tmp", false, "Retain the temporary files created during installation")
installCmd.Flags().String("language", "", "Comma-separated list of language codes to prefer for cask installation")
installCmd.Flags().String("mdimporterdir", "", "Target location for Spotlight Plugins")
installCmd.Flags().Bool("no-binaries", false, "Disable linking of helper executables")
installCmd.Flags().Bool("no-quarantine", false, "Disable quarantining of downloads")
installCmd.Flags().Bool("only-dependencies", false, "Install the dependencies with specified options")
installCmd.Flags().Bool("overwrite", false, "Delete files that already exist in the prefix while linking")
installCmd.Flags().String("prefpanedir", "", "Target location for Preference Panes")
installCmd.Flags().String("qlplugindir", "", "Target location for QuickLook Plugins")
installCmd.Flags().Bool("quarantine", false, "Enable quarantining of downloads")
installCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
installCmd.Flags().Bool("require-sha", false, "Require all casks to have a checksum.")
installCmd.Flags().String("screen-saverdir", "", "Target location for Screen Savers (default:")
installCmd.Flags().String("servicedir", "", "Target location for Services (default:")
installCmd.Flags().Bool("skip-cask-deps", false, "Skip installing cask dependencies")
installCmd.Flags().BoolP("verbose", "v", false, "Print the verification and postinstall steps")
installCmd.Flags().String("vst-plugindir", "", "Target location for VST Plugins (default:")
installCmd.Flags().String("vst3-plugindir", "", "Target location for VST3 Plugins (default:")
rootCmd.AddCommand(installCmd)

carapace.Gen(installCmd).FlagCompletion(carapace.ActionMap{
"appdir": carapace.ActionDirectories(),
"audio-unit-plugindir": carapace.ActionDirectories(),
"colorpickerdir": carapace.ActionDirectories(),
"dictionarydir": carapace.ActionDirectories(),
"fontdir": carapace.ActionDirectories(),
"input-methoddir": carapace.ActionDirectories(),
"internet-plugindir": carapace.ActionDirectories(),
"mdimporterdir": carapace.ActionDirectories(),
"prefpanedir": carapace.ActionDirectories(),
"qlplugindir": carapace.ActionDirectories(),
"screen-saverdir": carapace.ActionDirectories(),
"servicedir": carapace.ActionDirectories(),
"vst-plugindir": carapace.ActionDirectories(),
"vst3-plugindir": carapace.ActionDirectories(),
})

carapace.Gen(installCmd).PositionalAnyCompletion(
action.ActionSearch(installCmd),
)
}
42 changes: 42 additions & 0 deletions completers/brew_completer/cmd/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/brew_completer/cmd/action"
"github.com/spf13/cobra"
)

var listCmd = &cobra.Command{
Use: "list",
Short: "List all installed formulae and casks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(listCmd).Standalone()

listCmd.Flags().BoolS("1", "1", false, "Force output to be one entry per line")
listCmd.Flags().Bool("cask", false, "List only casks, or treat all named arguments as casks.")
listCmd.Flags().Bool("casks", false, "List only casks, or treat all named arguments as casks.")
listCmd.Flags().BoolP("debug", "d", false, "Display any debugging information.")
listCmd.Flags().Bool("formula", false, "List only formulae, or treat all named arguments as formulae.")
listCmd.Flags().Bool("formulae", false, "List only formulae, or treat all named arguments as formulae.")
listCmd.Flags().Bool("full-name", false, "Print formulae with fully-qualified names.")
listCmd.Flags().BoolP("help", "h", false, "Show this message.")
listCmd.Flags().BoolS("l", "l", false, "List formulae and/or casks in long format.")
listCmd.Flags().Bool("multiple", false, "Only show formulae with multiple versions installed")
listCmd.Flags().Bool("pinned", false, "List only pinned formulae")
listCmd.Flags().BoolP("quiet", "q", false, "Make some output more quiet.")
listCmd.Flags().BoolS("r", "r", false, "Reverse the order of the formulae")
listCmd.Flags().BoolS("t", "t", false, "Sort formulae and/or casks by time modified")
listCmd.Flags().Bool("unbrewed", false, "List files in Homebrew's prefix not installed by Homebrew.")
listCmd.Flags().BoolP("verbose", "v", false, "Make some output more verbose.")
listCmd.Flags().Bool("versions", false, "Show the version number for installed formulae")
rootCmd.AddCommand(listCmd)

carapace.Gen(listCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
return action.ActionList(listCmd).Invoke(c).Filter(c.Args).ToA()
}),
)
}
21 changes: 21 additions & 0 deletions completers/brew_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var rootCmd = &cobra.Command{
Use: "brew",
Short: "The missing package manager for macOS",
Long: "https://brew.sh/",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

}
Loading

0 comments on commit 77d3323

Please sign in to comment.