Repository: alexellis/arkade (Go)

Issue:
Feature request: Add Consul to arkade get
<!--- Provide a general summary of the issue in the Title above -->

related to https://github.com/alexellis/arkade/issues/626

## Expected Behaviour
<!--- If you're describing a bug, tell us what should happen -->
<!--- If you're suggesting a change/improvement, tell us how it should work -->

`arkade get consul` to download [HashiCorp Consul CLI](https://www.consul.io/commands)

## Current Behaviour
<!--- If describing a bug, tell us what happens instead of the expected behavior -->
<!--- If suggesting a change/improvement, explain the difference from current behavior -->

Not implemented.

## Are you a GitHub Sponsor yet (Yes/No?)

<!-- Requests from sponsors take priority -->
<!--- Check at https://github.com/sponsors/alexellis -->

- [ ] Yes
- [x] No

## Possible Solution
<!--- Not obligatory, but suggest a fix/reason for the bug, -->
<!--- or ideas how to implement the addition or change -->

Add Consul as a downloadable tool.

https://github.com/hashicorp/consul
https://releases.hashicorp.com/consul/

## Context

Consul is a service mesh, created by HashiCorp.

<!--- How has this issue affected you? What are you trying to accomplish? -->
<!--- What would happen if this issue was not resolved for you in some way? -->
<!--- Providing context helps us come up with a solution that is most useful in the real world -->

## If requesting a CLI for "arkade get"

https://github.com/hashicorp/consul has 25K stars




Discussion:

Patch:
diff --git a/README.md b/README.md
index d8cecbc57..147fd1854 100644
--- a/README.md
+++ b/README.md
@@ -779,6 +779,7 @@ There are 56 apps that you can install on your cluster.
 | [clusterctl](https://github.com/kubernetes-sigs/cluster-api)                 | The clusterctl CLI tool handles the lifecycle of a Cluster API management cluster                                                                               |
 | [cmctl](https://github.com/cert-manager/cert-manager)                        | cmctl is a CLI tool that helps you manage cert-manager and its resources inside your cluster.                                                                   |
 | [conftest](https://github.com/open-policy-agent/conftest)                    | Write tests against structured configuration data using the Open Policy Agent Rego query language                                                               |
+| [consul](https://github.com/hashicorp/consul)                                | A solution to connect and configure applications across dynamic, distributed infrastructure                                                                     |
 | [copa](https://github.com/project-copacetic/copacetic)                       | CLI for patching container images                                                                                                                               |
 | [cosign](https://github.com/sigstore/cosign)                                 | Container Signing, Verification and Storage in an OCI registry.                                                                                                 |
 | [cr](https://github.com/helm/chart-releaser)                                 | Hosting Helm Charts via GitHub Pages and Releases                                                                                                               |
@@ -913,6 +914,6 @@ There are 56 apps that you can install on your cluster.
 | [waypoint](https://github.com/hashicorp/waypoint)                            | Easy application deployment for Kubernetes and Amazon ECS                                                                                                       |
 | [yq](https://github.com/mikefarah/yq)                                        | Portable command-line YAML processor.                                                                                                                           |
 | [yt-dlp](https://github.com/yt-dlp/yt-dlp)                                   | Fork of youtube-dl with additional features and fixes                                                                                                           |
-There are 153 tools, use `arkade get NAME` to download one.
+There are 154 tools, use `arkade get NAME` to download one.
 
 > Note to contributors, run `arkade get --format markdown` to generate this list
diff --git a/pkg/get/tools.go b/pkg/get/tools.go
index 518d17274..080e0f6de 100644
--- a/pkg/get/tools.go
+++ b/pkg/get/tools.go
@@ -819,6 +819,31 @@ https://github.com/inlets/inletsctl/releases/download/{{.Version}}/{{$fileName}}
 		{{.Version}}/{{.Name}}-{{.VersionNumber}}-{{$osStr}}-{{$archStr}}.{{$extStr}}`,
 		})
 
+	tools = append(tools,
+		Tool{
+			Owner:           "hashicorp",
+			Repo:            "consul",
+			Name:            "consul",
+			VersionStrategy: GitHubVersionStrategy,
+			Description:     "A solution to connect and configure applications across dynamic, distributed infrastructure",
+			URLTemplate: `
+				{{$arch := ""}}
+				{{- if eq .Arch "x86_64" -}}
+				{{$arch = "amd64"}}
+				{{- else if or (eq .Arch "aarch64") (eq .Arch "arm64") -}}
+				{{$arch = "arm64"}}
+				{{- else if eq .Arch "armv7l" -}}
+				{{$arch = "arm"}}
+				{{- end -}}
+	
+				{{$os := .OS}}
+				{{ if HasPrefix .OS "ming" -}}
+				{{$os = "windows"}}
+				{{- end -}}
+	
+				https://releases.hashicorp.com/{{.Name}}/{{.VersionNumber}}/{{.Name}}_{{.VersionNumber}}_{{$os}}_{{$arch}}.zip`,
+		})
+
 	tools = append(tools,
 		Tool{
 			Owner:           "hashicorp",
@@ -830,9 +855,7 @@ https://github.com/inlets/inletsctl/releases/download/{{.Version}}/{{$fileName}}
 			{{$arch := ""}}
 			{{- if eq .Arch "x86_64" -}}
 			{{$arch = "amd64"}}
-			{{- else if eq .Arch "arm64" -}}
-			{{$arch = "arm64"}}
-			{{- else if eq .Arch "aarch64" -}}
+			{{- else if or (eq .Arch "aarch64") (eq .Arch "arm64") -}}
 			{{$arch = "arm64"}}
 			{{- else if eq .Arch "armv7l" -}}
 			{{$arch = "arm"}}


Test patch:
diff --git a/pkg/get/get_test.go b/pkg/get/get_test.go
index f3d2ca7ab..fef593d2e 100644
--- a/pkg/get/get_test.go
+++ b/pkg/get/get_test.go
@@ -246,35 +246,35 @@ func Test_GetDownloadURLs(t *testing.T) {
 	}{
 		{
 			name:    "kubectl",
-			url:     "https://dl.k8s.io/release/" + kubectlVersion + "/bin/linux/amd64/kubectl",
+			url:     "https://dl.k8s.io/release/v1.29.1/bin/linux/amd64/kubectl",
 			version: kubectlVersion,
 			os:      "linux",
 			arch:    "x86_64",
 		},
 		{
 			name:    "kubectl",
-			url:     "https://dl.k8s.io/release/" + kubectlVersion + "/bin/darwin/amd64/kubectl",
+			url:     "https://dl.k8s.io/release/v1.29.1/bin/darwin/amd64/kubectl",
 			version: kubectlVersion,
 			os:      "darwin",
 			arch:    "x86_64",
 		},
 		{
 			name:    "kubectl",
-			url:     "https://dl.k8s.io/release/" + kubectlVersion + "/bin/linux/arm64/kubectl",
+			url:     "https://dl.k8s.io/release/v1.29.1/bin/linux/arm64/kubectl",
 			version: kubectlVersion,
 			os:      "linux",
 			arch:    "aarch64",
 		},
 		{
 			name:    "kubectl",
-			url:     "https://dl.k8s.io/release/" + kubectlVersion + "/bin/darwin/arm64/kubectl",
+			url:     "https://dl.k8s.io/release/v1.29.1/bin/darwin/arm64/kubectl",
 			version: kubectlVersion,
 			os:      "darwin",
 			arch:    archDarwinARM64,
 		},
 		{
 			name:    "kubectl",
-			url:     "https://dl.k8s.io/release/" + kubectlVersion + "/bin/linux/amd64/kubectl",
+			url:     "https://dl.k8s.io/release/v1.29.1/bin/linux/amd64/kubectl",
 			version: kubectlVersion,
 			os:      "linux",
 			arch:    "x86_64",
@@ -1250,37 +1250,37 @@ func Test_DownloadPopeye(t *testing.T) {
 			os:      "ming",
 			arch:    arch64bit,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Windows_amd64.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Windows_amd64.tar.gz",
 		},
 		{
 			os:      "linux",
 			arch:    arch64bit,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Linux_amd64.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Linux_amd64.tar.gz",
 		},
 		{
 			os:      "darwin",
 			arch:    arch64bit,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Darwin_amd64.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Darwin_amd64.tar.gz",
 		},
 		{
 			os:      "darwin",
 			arch:    archDarwinARM64,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Darwin_arm64.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Darwin_arm64.tar.gz",
 		},
 		{
 			os:      "linux",
 			arch:    archARM64,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Linux_arm64.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Linux_arm64.tar.gz",
 		},
 		{
 			os:      "linux",
 			arch:    archARM7,
 			version: toolVersion,
-			url:     "https://github.com/derailed/popeye/releases/download/" + toolVersion + "/popeye_Linux_armv7.tar.gz",
+			url:     "https://github.com/derailed/popeye/releases/download/v0.21.2/popeye_Linux_armv7.tar.gz",
 		},
 	}
 
@@ -1436,6 +1436,64 @@ func Test_DownloadWaypoint(t *testing.T) {
 	}
 }
 
+func Test_DownloadConsul(t *testing.T) {
+	tools := MakeTools()
+	name := "consul"
+
+	tool := getTool(name, tools)
+
+	const toolVersion = "1.18.1"
+
+	tests := []test{
+		{
+			os:      "mingw64_nt-10.0-18362",
+			arch:    arch64bit,
+			version: toolVersion,
+			url:     `https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_windows_amd64.zip`,
+		},
+		{
+			os:      "linux",
+			arch:    arch64bit,
+			version: toolVersion,
+			url:     "https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip",
+		},
+		{
+			os:      "linux",
+			arch:    archARM7,
+			version: toolVersion,
+			url:     "https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_arm.zip",
+		},
+		{
+			os:      "linux",
+			arch:    archARM64,
+			version: toolVersion,
+			url:     "https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_arm64.zip",
+		},
+		{
+			os:      "darwin",
+			arch:    archDarwinARM64,
+			version: toolVersion,
+			url:     "https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_darwin_arm64.zip",
+		},
+		{
+			os:      "darwin",
+			arch:    arch64bit,
+			version: toolVersion,
+			url:     "https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_darwin_amd64.zip",
+		},
+	}
+
+	for _, tc := range tests {
+		got, err := tool.GetURL(tc.os, tc.arch, tc.version, false)
+		if err != nil {
+			t.Fatal(err)
+		}
+		if got != tc.url {
+			t.Errorf("\nwant: %s, \n got: %s", tc.url, got)
+		}
+	}
+}
+
 func Test_DownloadTerraform(t *testing.T) {
 	tools := MakeTools()
 	name := "terraform"
@@ -6827,25 +6885,25 @@ func Test_DownloadAtuin(t *testing.T) {
 			os:      "darwin",
 			arch:    archDarwinARM64,
 			version: toolVersion,
-			url:     "https://github.com/atuinsh/atuin/releases/download/" + toolVersion + "/atuin-" + toolVersion + "-aarch64-apple-darwin.tar.gz",
+			url:     "https://github.com/atuinsh/atuin/releases/download/v18.2.0/atuin-v18.2.0-aarch64-apple-darwin.tar.gz",
 		},
 		{
 			os:      "linux",
 			arch:    archARM64,
 			version: toolVersion,
-			url:     "https://github.com/atuinsh/atuin/releases/download/" + toolVersion + "/atuin-" + toolVersion + "-aarch64-unknown-linux-gnu.tar.gz",
+			url:     "https://github.com/atuinsh/atuin/releases/download/v18.2.0/atuin-v18.2.0-aarch64-unknown-linux-gnu.tar.gz",
 		},
 		{
 			os:      "linux",
 			arch:    arch64bit,
 			version: toolVersion,
-			url:     "https://github.com/atuinsh/atuin/releases/download/" + toolVersion + "/atuin-" + toolVersion + "-x86_64-unknown-linux-gnu.tar.gz",
+			url:     "https://github.com/atuinsh/atuin/releases/download/v18.2.0/atuin-v18.2.0-x86_64-unknown-linux-gnu.tar.gz",
 		},
 		{
 			os:      "darwin",
 			arch:    arch64bit,
 			version: toolVersion,
-			url:     "https://github.com/atuinsh/atuin/releases/download/" + toolVersion + "/atuin-" + toolVersion + "-x86_64-apple-darwin.tar.gz",
+			url:     "https://github.com/atuinsh/atuin/releases/download/v18.2.0/atuin-v18.2.0-x86_64-apple-darwin.tar.gz",
 		},
 	}