Skip to content

Commit

Permalink
Add 'rg'
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Sep 7, 2024
1 parent 9952e09 commit c114cf2
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 1 deletion.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions tools/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions tools/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions tools/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion tools/tables.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//nolint:dupl
package tools

var Arch = map[string]map[string]map[string]string{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
Flyctl = "flyctl"
K9s = "k9s"
Kubectx = "kubectx"
Ripgrep = "rg"
UPX = "upx"
Xh = "xh"
Yj = "yj"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c114cf2

Please sign in to comment.