Skip to content

Commit e61a7f3

Browse files
author
licong
committed
add --version flag
1 parent 4888c51 commit e61a7f3

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

.github/workflows/release.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ jobs:
1414
stable: 'true'
1515
go-version: '^1.16.1'
1616
- name: build
17-
run: go get github.com/mitchellh/gox && mkdir dist && perl build.pl && ls -al dist/
17+
run: |
18+
export PATH=$PATH:$(go env GOPATH)/bin
19+
go get github.com/mitchellh/gox
20+
mkdir dist
21+
perl build.pl
22+
ls -al dist/
1823
- name: Upload binaries to release
1924
uses: svenstaro/upload-release-action@v2
2025
with:
@@ -24,4 +29,4 @@ jobs:
2429
asset_name: mything
2530
tag: ${{ github.ref }}
2631
overwrite: true
27-
file_glob: true
32+
file_glob: true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.exe
1+
*.exe
2+
with-env

main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,32 @@
11
package main
22

33
import (
4+
"flag"
45
"fmt"
56
"os"
67
"os/exec"
78
"path/filepath"
9+
"runtime/debug"
810

911
"github.com/joho/godotenv"
1012
)
1113

14+
var (
15+
showVersion = flag.Bool("version", false, "pring progream version")
16+
)
17+
1218
// first load env from ~/.env
1319
// second load env from .env
1420
func init() {
21+
flag.Parse()
22+
if *showVersion {
23+
PrintVersion()
24+
os.Exit(0)
25+
}
26+
if len(os.Args) < 2 {
27+
fmt.Printf("Usage: with-env {command}\n")
28+
os.Exit(1)
29+
}
1530
home, _ := os.UserHomeDir()
1631
loadEnv(filepath.Join(home, ".env"), ".env")
1732
}
@@ -33,3 +48,10 @@ func main() {
3348
os.Exit(1)
3449
}
3550
}
51+
52+
func PrintVersion() {
53+
info, ok := debug.ReadBuildInfo()
54+
if ok {
55+
println(info.Main.Version, info.Main.Sum)
56+
}
57+
}

0 commit comments

Comments
 (0)