Skip to content

Commit

Permalink
Ensure dependencies are present before running any command.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnutix committed Nov 29, 2023
1 parent 853ab47 commit 27568af
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ Creating the Alfred node image is done using [Packer](https://www.packer.io/) in

- bash
- docker
- tar
- ssh
- zstd
7 changes: 7 additions & 0 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"os"
"os/exec"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 27568af

Please sign in to comment.