diff --git a/main.go b/main.go index 4053535..13dbaa4 100644 --- a/main.go +++ b/main.go @@ -134,6 +134,14 @@ func main() { }, } + shellcheckCmd := &cobra.Command{ + Use: tools.Shellcheck, + Short: "A static analysis tool for shell scripts", + Run: func(cmd *cobra.Command, args []string) { + run(tools.Shellcheck) + }, + } + upxCmd := &cobra.Command{ Use: tools.UPX, Short: "The Ultimate Packer for eXecutables", @@ -173,6 +181,7 @@ func main() { rootCmd.AddCommand(k9sCmd) rootCmd.AddCommand(kubectxCmd) rootCmd.AddCommand(ripgrepCmd) + rootCmd.AddCommand(shellcheckCmd) rootCmd.AddCommand(upxCmd) rootCmd.AddCommand(xhCmd) rootCmd.AddCommand(yjCmd) diff --git a/tools/asset.go b/tools/asset.go index 9a67ce0..d5333e4 100644 --- a/tools/asset.go +++ b/tools/asset.go @@ -43,6 +43,14 @@ func (t *Tool) AssetRipgrep() { t.Asset.WithinArchive = path.Join(baseName, t.Name) } +func (t *Tool) AssetShellcheck() { + baseName := fmt.Sprintf("shellcheck-%v.%v.%v", t.Version, t.OS, t.Arch) + t.Asset.Name = baseName + ".tar.xz" + + folderName := fmt.Sprintf("shellcheck-%v", t.Version) + t.Asset.WithinArchive = path.Join(folderName, 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 b594b88..8434a6b 100644 --- a/tools/asset_test.go +++ b/tools/asset_test.go @@ -43,6 +43,10 @@ func (s *AssetTestSuite) TestDestination() { name: Ripgrep, dest: "/usr/local/bin/rg", }, + { + name: Shellcheck, + dest: "/usr/local/bin/shellcheck", + }, { name: UPX, dest: "/usr/local/bin/upx", @@ -124,6 +128,13 @@ func (s *AssetTestSuite) TestIsBinary() { version: "14.1.0", binary: false, }, + { + name: Shellcheck, + arch: "amd64", + os: "linux", + version: "v0.10.0", + binary: false, + }, { name: UPX, arch: "amd64", @@ -216,6 +227,13 @@ func (s *AssetTestSuite) TestName() { version: "14.1.0", filename: "ripgrep-14.1.0-x86_64-unknown-linux-musl.tar.gz", }, + { + name: Shellcheck, + arch: "amd64", + os: "linux", + version: "v0.10.0", + filename: "shellcheck-v0.10.0.linux.x86_64.tar.xz", + }, { name: UPX, arch: "amd64", @@ -301,6 +319,13 @@ func (s *AssetTestSuite) TestWithinArchive() { version: "14.1.0", withinArchive: "ripgrep-14.1.0-x86_64-unknown-linux-musl/rg", }, + { + name: Shellcheck, + arch: "amd64", + os: "linux", + version: "v0.10.0", + withinArchive: "shellcheck-v0.10.0/shellcheck", + }, { name: UPX, arch: "amd64", diff --git a/tools/runtime_test.go b/tools/runtime_test.go index 332ccc3..46e324f 100644 --- a/tools/runtime_test.go +++ b/tools/runtime_test.go @@ -238,6 +238,50 @@ func (s *RuntimeTestSuite) TestRipgrepRuntime() { } } +func (s *RuntimeTestSuite) TestShellcheckRuntime() { + table := []struct { + arch string + os string + archOut string + osOut string + }{ + { + arch: "amd64", + os: "linux", + archOut: "x86_64", + osOut: "linux", + }, + { + arch: "amd64", + os: "darwin", + archOut: "x86_64", + osOut: "darwin", + }, + { + arch: "arm64", + os: "linux", + archOut: "aarch64", + osOut: "linux", + }, + { + arch: "arm64", + os: "darwin", + archOut: "aarch64", + osOut: "darwin", + }, + } + + for _, tt := range table { + t := &Tool{ + Name: Shellcheck, + } + 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 df5fa79..3bcda01 100644 --- a/tools/tables.go +++ b/tools/tables.go @@ -69,6 +69,16 @@ var Arch = map[string]map[string]map[string]string{ "arm64": "aarch64", }, }, + Shellcheck: { + "darwin": { + "amd64": "x86_64", + "arm64": "aarch64", + }, + "linux": { + "amd64": "x86_64", + "arm64": "aarch64", + }, + }, UPX: { "linux": { "amd64": "amd64", @@ -172,6 +182,16 @@ var OS = map[string]map[string]map[string]string{ "arm64": "unknown-linux-gnu", }, }, + Shellcheck: { + "darwin": { + "amd64": "darwin", + "arm64": "darwin", + }, + "linux": { + "amd64": "linux", + "arm64": "linux", + }, + }, Xh: { "darwin": { "amd64": "apple-darwin", @@ -202,6 +222,7 @@ var URL = map[string]string{ K9s: "https://github.com/derailed/k9s", Kubectx: "https://github.com/ahmetb/kubectx", Ripgrep: "https://github.com/BurntSushi/ripgrep", + Shellcheck: "https://github.com/koalaman/shellcheck", 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 cff9b92..90c18d3 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -19,6 +19,7 @@ const ( K9s = "k9s" Kubectx = "kubectx" Ripgrep = "rg" + Shellcheck = "shellcheck" UPX = "upx" Xh = "xh" Yj = "yj" @@ -168,6 +169,8 @@ func (t *Tool) SetAsset() error { t.AssetKubectx() case Ripgrep: t.AssetRipgrep() + case Shellcheck: + t.AssetShellcheck() case UPX: t.AssetUPX() case Xh: diff --git a/tools/tools_test.go b/tools/tools_test.go index 39639f6..3b871fb 100644 --- a/tools/tools_test.go +++ b/tools/tools_test.go @@ -63,6 +63,10 @@ func (s *ToolsTestSuite) TestSetURL() { name: Ripgrep, url: "https://github.com/BurntSushi/ripgrep/releases", }, + { + name: Shellcheck, + url: "https://github.com/koalaman/shellcheck/releases", + }, { name: UPX, url: "https://github.com/upx/upx/releases",