Skip to content

Commit

Permalink
fix: add LookupPath and LookupEnv for cmd module
Browse files Browse the repository at this point in the history
  • Loading branch information
Deny Prasetyo committed Nov 23, 2021
1 parent a8a911d commit b02b411
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions pkg/cmd/lookup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cmd

import (
"log"
"os"
"os/exec"
)

func LookPathDefault(executableName string, defaultPath string) (binaryPath string) {
path, err := exec.LookPath(executableName)
if err != nil {
return defaultPath
}
return path
}

func LookPath(executableName string) (binaryPath string) {
path, err := exec.LookPath(executableName)
if err != nil {
log.Panicln(err.Error())
}
return path
}

func LookupEnvDefault(key string, fallback string) string {
if value, ok := os.LookupEnv(key); ok {
return value
}
return fallback
}

func LookupEnv(key string) string {
value, ok := os.LookupEnv(key)
if !ok {
log.Panicf("env key %s not found\n", key)
}
return value
}

0 comments on commit b02b411

Please sign in to comment.