Skip to content

Commit

Permalink
Add --stash mode to get
Browse files Browse the repository at this point in the history
The stash flag stores binaries in the arkade working directory,
so that users do not need to move files into /usr/local/bin/

Also adds unit test to cover #173

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Aug 9, 2020
1 parent 8c0b60f commit 05b03a1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
51 changes: 29 additions & 22 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ func MakeGet() *cobra.Command {
Long: `The get command downloads a CLI or application from the specific tool's
releases or downloads page. The tool is usually downloaded in binary format
and provides a fast and easy alternative to a package manager.`,
Example: ` arkade get faas-cli
arkade get helm
arkade get kind
arkade get kubectx`,
Example: ` arkade get helm
arkade get linkerd2 --stash
arkade get --help`,
SilenceUsage: true,
}

command.Flags().Bool("stash", false, "When set to true, stash binary in HOME/.arkade/bin/, otherwise store in /tmp/")

command.RunE = func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
fmt.Println(arkadeGet)
const arkadeGet = `Use "arkade get TOOL" to download a tool or application:`

buf := ""
for _, t := range tools {
buf = buf + t.Name + "\n"
}
fmt.Println(arkadeGet + "\n" + buf)
return nil
}
var tool *get.Tool
Expand All @@ -52,35 +59,35 @@ and provides a fast and easy alternative to a package manager.`,
arch, operatingSystem := env.GetClientArch()
version := ""

outFilePath, finalName, err := get.Download(tool, arch, operatingSystem, version, get.DownloadTempDir)
stash, _ := command.Flags().GetBool("stash")
dlMode := get.DownloadTempDir
if stash {
dlMode = get.DownloadArkadeDir
}

outFilePath, finalName, err := get.Download(tool, arch, operatingSystem, version, dlMode)

if err != nil {
return err
}

fmt.Printf(`Tool written to: %s
fmt.Printf("Tool written to: %s\n\n", outFilePath)

Run the following to copy to install the tool:
if dlMode == get.DownloadTempDir {
fmt.Printf(`Run the following to copy to install the tool:
chmod +x %s
sudo install -m 755 %s /usr/local/bin/%s
`, outFilePath, outFilePath, outFilePath, finalName)
`, outFilePath, outFilePath, finalName)
} else {
fmt.Printf(`Run the following to add the (%s) binary to your PATH variable
export PATH=$PATH:$HOME/.arkade/bin/
`, finalName)

}
return err
}

return command
}

const arkadeGet = `Use "arkade get TOOL" to download a tool or application:
- faas-cli
- helm
- inletsctl
- k3d
- k3sup
- kind
- kubectl
- kubectx
- kubeseal
`
3 changes: 1 addition & 2 deletions pkg/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"html/template"
"log"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -178,7 +177,7 @@ func getByDownloadTemplate(tool Tool, os, arch, version string) (string, error)
"Arch": arch,
"Version": version,
}
log.Println(inputs)

err = t.Execute(&buf, inputs)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/get/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ https://get.helm.sh/helm-{{.Version}}-{{$os}}-{{$arch}}.{{$ext}}`,
Version: "v1.18.0",
URLTemplate: `{{$arch := "arm"}}
{{- if eq .Arch "x86_64" -}}
{{- if eq .Arch "x86_64" -}}
{{$arch = "amd64"}}
{{- end -}}
Expand Down

0 comments on commit 05b03a1

Please sign in to comment.