-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cosmos): also look for
ag-chain-cosmos
in the agd
directory
- Loading branch information
1 parent
f0e42b1
commit f598d40
Showing
2 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
) | ||
|
||
// FindBinaryNextToMe looks for binName next to the current executable. | ||
// It returns an absolute filename for binName, or an error. | ||
func FindBinaryNextToMe(binName string) (string, error) { | ||
ex, err := os.Executable() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Calculate the binary's filename. | ||
bin := filepath.Join(filepath.Dir(ex), binName) | ||
|
||
// Take the absolute path. | ||
bin, err = filepath.Abs(bin) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Check that the binary exists. | ||
if _, err := os.Stat(bin); err != nil { | ||
return "", err | ||
} | ||
return bin, nil | ||
} | ||
|
||
// FindBinary looks for binName in the following locations: | ||
// 1. The executable's directory | ||
// 2. The system PATH | ||
// | ||
// It returns the absolute filename for binName if it is found, otherwise an | ||
// error. | ||
func FindBinary(binName string) (string, error) { | ||
if binary, err := FindBinaryNextToMe(binName); err == nil { | ||
return binary, nil | ||
} | ||
|
||
// Check the system PATH. | ||
return exec.LookPath(binName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters