mirror of
https://github.com/FiloSottile/age.git
synced 2026-09-25 17:34:32 +00:00
cmd/age,cmd/age-keygen: add -version flag
Fixes #157 Fixes #101 Closes #97
This commit is contained in:
committed by
Filippo Valsorda
parent
f8507c1cac
commit
0522803919
@@ -11,20 +11,39 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"filippo.io/age"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
)
|
||||
|
||||
// Version can be set at link time to override debug.BuildInfo.Main.Version,
|
||||
// which is "(devel)" when building from within the module. See
|
||||
// golang.org/issue/29814 and golang.org/issue/29228.
|
||||
var Version string
|
||||
|
||||
func main() {
|
||||
log.SetFlags(0)
|
||||
|
||||
outFlag := flag.String("o", "", "output to `FILE` (default stdout)")
|
||||
versionFlag := flag.Bool("version", false, "print the version")
|
||||
flag.Parse()
|
||||
if len(flag.Args()) != 0 {
|
||||
log.Fatalf("age-keygen takes no arguments")
|
||||
}
|
||||
if *versionFlag {
|
||||
if Version != "" {
|
||||
fmt.Println(Version)
|
||||
return
|
||||
}
|
||||
if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
||||
fmt.Println(buildInfo.Main.Version)
|
||||
return
|
||||
}
|
||||
fmt.Println("(unknown)")
|
||||
return
|
||||
}
|
||||
|
||||
out := os.Stdout
|
||||
if name := *outFlag; name != "" {
|
||||
|
||||
Reference in New Issue
Block a user