Skip to content

Commit

Permalink
Add 'shellcheck'
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Sep 9, 2024
1 parent 3b7c1d4 commit 959bb17
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 0 deletions.
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tools/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
25 changes: 25 additions & 0 deletions tools/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions tools/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tools/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
K9s = "k9s"
Kubectx = "kubectx"
Ripgrep = "rg"
Shellcheck = "shellcheck"
UPX = "upx"
Xh = "xh"
Yj = "yj"
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tools/tools_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 959bb17

Please sign in to comment.