diff --git a/main.go b/main.go index 4f2dcbe..4053535 100644 --- a/main.go +++ b/main.go @@ -126,6 +126,14 @@ func main() { }, } + ripgrepCmd := &cobra.Command{ + Use: tools.Ripgrep, + Short: "Recursively searches directories for a regex pattern", + Run: func(cmd *cobra.Command, args []string) { + run(tools.Ripgrep) + }, + } + upxCmd := &cobra.Command{ Use: tools.UPX, Short: "The Ultimate Packer for eXecutables", @@ -164,6 +172,7 @@ func main() { rootCmd.AddCommand(flyctlCmd) rootCmd.AddCommand(k9sCmd) rootCmd.AddCommand(kubectxCmd) + rootCmd.AddCommand(ripgrepCmd) rootCmd.AddCommand(upxCmd) rootCmd.AddCommand(xhCmd) rootCmd.AddCommand(yjCmd) diff --git a/tools/asset.go b/tools/asset.go index df7eb4c..9a67ce0 100644 --- a/tools/asset.go +++ b/tools/asset.go @@ -37,6 +37,12 @@ func (t *Tool) AssetKubectx() { t.Asset.Name = fmt.Sprintf("kubectx_%v_%v_%v.tar.gz", t.Version, t.OS, t.Arch) } +func (t *Tool) AssetRipgrep() { + baseName := fmt.Sprintf("ripgrep-%v-%v-%v", t.Version, t.Arch, t.OS) + t.Asset.Name = baseName + ".tar.gz" + t.Asset.WithinArchive = path.Join(baseName, t.Name) +} + func (t *Tool) AssetUPX() { baseName := fmt.Sprintf("upx-%v-%v_%v", t.TrimVersion(), t.Arch, t.OS) t.Asset.Name = baseName + ".tar.xz" diff --git a/tools/asset_test.go b/tools/asset_test.go index 877aa1e..b594b88 100644 --- a/tools/asset_test.go +++ b/tools/asset_test.go @@ -39,6 +39,10 @@ func (s *AssetTestSuite) TestDestination() { name: K9s, dest: "/usr/local/bin/k9s", }, + { + name: Ripgrep, + dest: "/usr/local/bin/rg", + }, { name: UPX, dest: "/usr/local/bin/upx", @@ -113,6 +117,13 @@ func (s *AssetTestSuite) TestIsBinary() { version: "v0.25.4", binary: false, }, + { + name: Ripgrep, + arch: "amd64", + os: "linux", + version: "14.1.0", + binary: false, + }, { name: UPX, arch: "amd64", @@ -198,6 +209,13 @@ func (s *AssetTestSuite) TestName() { version: "v0.9.5", filename: "kubectx_v0.9.5_darwin_arm64.tar.gz", }, + { + name: Ripgrep, + arch: "amd64", + os: "linux", + version: "14.1.0", + filename: "ripgrep-14.1.0-x86_64-unknown-linux-musl.tar.gz", + }, { name: UPX, arch: "amd64", @@ -276,6 +294,13 @@ func (s *AssetTestSuite) TestWithinArchive() { version: "v0.25.4", withinArchive: "k9s", }, + { + name: Ripgrep, + arch: "amd64", + os: "linux", + version: "14.1.0", + withinArchive: "ripgrep-14.1.0-x86_64-unknown-linux-musl/rg", + }, { name: UPX, arch: "amd64", diff --git a/tools/runtime_test.go b/tools/runtime_test.go index e770f4a..332ccc3 100644 --- a/tools/runtime_test.go +++ b/tools/runtime_test.go @@ -194,6 +194,50 @@ func (s *RuntimeTestSuite) TestK9sRuntime() { } } +func (s *RuntimeTestSuite) TestRipgrepRuntime() { + table := []struct { + arch string + os string + archOut string + osOut string + }{ + { + arch: "amd64", + os: "linux", + archOut: "x86_64", + osOut: "unknown-linux-musl", + }, + { + arch: "amd64", + os: "darwin", + archOut: "x86_64", + osOut: "apple-darwin", + }, + { + arch: "arm64", + os: "linux", + archOut: "aarch64", + osOut: "unknown-linux-gnu", + }, + { + arch: "arm64", + os: "darwin", + archOut: "aarch64", + osOut: "apple-darwin", + }, + } + + for _, tt := range table { + t := &Tool{ + Name: Ripgrep, + } + err := t.SetRuntime(tt.arch, tt.os) + s.Nil(err) + s.Equal(tt.archOut, t.Arch) + s.Equal(tt.osOut, t.OS) + } +} + func (s *RuntimeTestSuite) TestXhRuntime() { table := []struct { arch string diff --git a/tools/tables.go b/tools/tables.go index ff23853..df5fa79 100644 --- a/tools/tables.go +++ b/tools/tables.go @@ -1,4 +1,3 @@ -//nolint:dupl package tools var Arch = map[string]map[string]map[string]string{ @@ -60,6 +59,16 @@ var Arch = map[string]map[string]map[string]string{ "arm64": "arm64", }, }, + Ripgrep: { + "darwin": { + "amd64": "x86_64", + "arm64": "aarch64", + }, + "linux": { + "amd64": "x86_64", + "arm64": "aarch64", + }, + }, UPX: { "linux": { "amd64": "amd64", @@ -153,6 +162,16 @@ var OS = map[string]map[string]map[string]string{ "arm64": "linux", }, }, + Ripgrep: { + "darwin": { + "amd64": "apple-darwin", + "arm64": "apple-darwin", + }, + "linux": { + "amd64": "unknown-linux-musl", + "arm64": "unknown-linux-gnu", + }, + }, Xh: { "darwin": { "amd64": "apple-darwin", @@ -182,6 +201,7 @@ var URL = map[string]string{ Flyctl: "https://github.com/superfly/flyctl", K9s: "https://github.com/derailed/k9s", Kubectx: "https://github.com/ahmetb/kubectx", + Ripgrep: "https://github.com/BurntSushi/ripgrep", UPX: "https://github.com/upx/upx", Xh: "https://github.com/ducaale/xh", Yj: "https://github.com/sclevine/yj", diff --git a/tools/tools.go b/tools/tools.go index 43857c7..d9d3706 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -18,6 +18,7 @@ const ( Flyctl = "flyctl" K9s = "k9s" Kubectx = "kubectx" + Ripgrep = "rg" UPX = "upx" Xh = "xh" Yj = "yj" @@ -157,6 +158,8 @@ func (t *Tool) SetAsset() error { t.AssetK9s() case Kubectx: t.AssetKubectx() + case Ripgrep: + t.AssetRipgrep() case UPX: t.AssetUPX() case Xh: diff --git a/tools/tools_test.go b/tools/tools_test.go index d2e1ab6..39639f6 100644 --- a/tools/tools_test.go +++ b/tools/tools_test.go @@ -59,6 +59,10 @@ func (s *ToolsTestSuite) TestSetURL() { name: Kubectx, url: "https://github.com/ahmetb/kubectx/releases", }, + { + name: Ripgrep, + url: "https://github.com/BurntSushi/ripgrep/releases", + }, { name: UPX, url: "https://github.com/upx/upx/releases",