From 27568afee7355032868a966c913f0a8234306fdc Mon Sep 17 00:00:00 2001 From: Dorian Villet Date: Wed, 29 Nov 2023 11:57:03 +0100 Subject: [PATCH] Ensure dependencies are present before running any command. --- README.md | 2 +- client/main.go | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d9e93d..50002a4 100644 --- a/README.md +++ b/README.md @@ -63,5 +63,5 @@ Creating the Alfred node image is done using [Packer](https://www.packer.io/) in - bash - docker -- tar +- ssh - zstd diff --git a/client/main.go b/client/main.go index 5eaf9a3..1d1f0dd 100644 --- a/client/main.go +++ b/client/main.go @@ -5,6 +5,7 @@ import ( "fmt" "net" "os" + "os/exec" "strings" "github.com/fatih/color" @@ -33,6 +34,12 @@ var alfredCmd = &cobra.Command{ SilenceErrors: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) (err error) { + dependencies := []string{"bash", "docker", "ssh", "zstd"} + command := exec.Command("/bin/which", dependencies...) + if err := command.Run(); err != nil { + return fmt.Errorf("missing mandatory dependencies (%s): %w", strings.Join(dependencies, ", "), err) + } + defer func() { if err != nil { err = fmt.Errorf("failed to connect to gRPC client: %w", err)