show version

This commit is contained in:
Timon Ringwald 2022-08-29 13:41:47 +02:00
parent f4ed6a3921
commit b3eb63251f
3 changed files with 13 additions and 0 deletions

2
go.mod
View File

@ -1,3 +1,5 @@
module git.milar.in/milarin/loadenv module git.milar.in/milarin/loadenv
go 1.18 go 1.18
require git.milar.in/milarin/buildinfo v1.0.0

2
go.sum
View File

@ -0,0 +1,2 @@
git.milar.in/milarin/buildinfo v1.0.0 h1:tw98GupUYl/0a/3aPGuezhE4wseycOSsbcLp70hy60U=
git.milar.in/milarin/buildinfo v1.0.0/go.mod h1:arI9ZoENOgcZcanv25k9y4dKDUhPp0buJrlVerGruas=

View File

@ -8,6 +8,8 @@ import (
"os" "os"
"os/exec" "os/exec"
"regexp" "regexp"
"git.milar.in/milarin/buildinfo"
) )
var ( var (
@ -15,11 +17,18 @@ var (
EnvVarRegex = regexp.MustCompile(`^(.*?)=(.*?)$`) EnvVarRegex = regexp.MustCompile(`^(.*?)=(.*?)$`)
EnvCommentRegex = regexp.MustCompile(`^[ \t]*#.*?$`) EnvCommentRegex = regexp.MustCompile(`^[ \t]*#.*?$`)
ShowVersion = flag.Bool("v", false, "show version and exit")
) )
func main() { func main() {
flag.Parse() flag.Parse()
if *ShowVersion {
buildinfo.Print(buildinfo.Options{})
return
}
envFile, err := os.Open(*EnvFilePath) envFile, err := os.Open(*EnvFilePath)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "could not open file '%s': %s\n", *EnvFilePath, err.(*os.PathError).Err) fmt.Fprintf(os.Stderr, "could not open file '%s': %s\n", *EnvFilePath, err.(*os.PathError).Err)